Quote:
Originally Posted by thelimpkid
I'm trying to use command-line arguments in an efficient way.
When I tried:
Code:
int main(int argc, char* argv)
{
if (argv[1] == "new")
{
cout << "Something New!\n";
}
return 0;
}
I wasn't able to get "Something New!" to print on the screen.
However, when I tried:
Code:
int main(int argc, char* argv)
{
string cla;
cla = argv[1];
if(cla == "new")
{
cout << "Something New!\n";
}
return 0;
}
I was able to get "Something New!" to print on the screen.
Why didn't it work on the first piece of code?
|
Hey here are the exact lines from the book i'm referring to learn c++..
"Testing how C++ compares quoted strings is more difficult. Instead of using the contents
of the string, the compiler uses the location of the strings in memory, which is a detail of the
compiler’s internal workings and has no bearing on anything practical. Thus, unless you know
how the compiler works, you cannot predict how it will compare two quoted strings. In other
words, don’t do that. Make sure you create
objects before you compare strings."
It seems you are learning c++ too..I can suggest "Exploring C++(Apress)"..