// chevy.cpp
// demonstrates some char [], char*, and string manipulations
// Run! LIVE! On the Internet
/* sample output
it's an identity Chevy!
it's a compare Chevy!
it's a !compare Chevy!
it's a strcmp array Chevy!
it's a strcmp carPtr Chevy!
*/
#include <iostream> // not <iostream.h>
#include <string> // not <string.h>
// #include <iostream.h>
// #include <string.h>
using namespace std;
int main(void)
{
string car = "Chevy";
if(car == "Chevy")
{
cout << "it's an identity Chevy!" << endl;
}
if(car.compare("Chevy") == 0)
{
cout << "it's a compare Chevy!" << endl;
}
if(!car.compare("Chevy"))
{
cout << "it's a !compare Chevy!" << endl;
}
char vehicle[] = {"Chevy"};
if(strcmp(vehicle, "Chevy") == 0)
{
cout << "it's a strcmp array Chevy!" << endl;
}
char* carPtr = vehicle;
if(strcmp(carPtr, "Chevy") == 0)
{
cout << "it's a strcmp carPtr Chevy!" << endl;
}
return 0;
}