if-else statement!!!

Can anybody tell me what is the error in this statement!!!
1
2
3
4
5
6
7
8
if(Status=="member")
           {
           cout<<"The user is a member"<<endl;
           }
           else
           {
               cout<<"This user status is not member"<<endl;
           }

This statement executes the else part if condition is true.....What the hell is wrong with this....????
Sorry to break it to ya: If the else part runs, the condition is false. No way around that.

What data type is Status? If it is a std::string or std::wstring, then comparison is case-sensitive.
Repeated punctuation does not make you more clear.

The problem is in Status == "member", assuming that Status is a char* rather than std::string. The * means a pointer. To compare pointers is to compare the addresses of memory locations they point to, not the data. One solution would be to make it an std::string. Another would be to write if(strcmp(Status, "member")==0) (You'll have to include <cstring>).
@webJose Status is char non-pointer variable....
Ok, so hamsterman is right: You must use strcmp() to compare strings. That function is case-sensitive. Use stricmp() for case-insensitive comparison, although I heard once that this one is not standard so your compiler might not provide it.

I also hope that when you say "non-pointer variable" you mean it is an array of char. Otherwise you cannot compare an entire string against a single character.
yes it is array of charchar Status[].......
You are declaring Status as a c-string rather a string so, you cannot make comparison like this. String type is a class in which the relational operator "==" is overloaded and you can compare objects(of string class) using this operator. However, in a c-string this functionality is not available. So, in order to make a comparison you have to use the strcmp() function. The correct syntax(in this case) will be if(strcmp(Status, "member")==0)
Topic archived. No new replies allowed.