logical operations for const char *

I have a simple question! why is this not true?

(d == "cplusplus")

when

const char *d = "cplusplus";


how should I do the comparison then?
Use strcmp() to compare the contents of C-strings. The reason it doesn't work is because they are pointers, and you are comparing the addresses, basically, not the contents of the strings.
Thanks a lot Zhuge.
You can also check it using
*d = "cplusplus";
rather than d.
This worked for me atleast!
it's strange, is it true that if we didn't use it for cout then it used as pointer (address) ? e.g:

1
2
3
4
char sentence [] = "new ones";

if (sentence == "new ones")
cout << "succeded\n";


it doesn't work. but when i do this:

 
cout << sentence << endl;


prints: new ones
Yeah, I noticed that too (Just today as a matter of fact) when trying to make a program that would check the equality of two strings (The actual problem was that I had to do that in the primitive compiler, Turbo C++ [Borland])
so this is true?

is it true that if we didn't use it for cout then it used as pointer (address) ?
is this a "yes"?
Apparently!
Topic archived. No new replies allowed.