Boolean operators on strings

Hi,

I was wondering if boolean operators worked on strings like they do on integers. I have some code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
if (input == "string1" || "string2")
{                                           
   cout << "outcome1";
}

else if (input == "string3" || "string4" || "string5")
{
   cout << "outcome2";
}

else 
{
   cout << "outcome3";
}


When input is "string1", the program prints "outcome1" as expected. However, when input is "string3", it also prints "outcome1". When i change the first "if" statement to:

1
2
3
4
if (input == "string1")
{                                           
   cout << "outcome1";
}


however, then string3 will give a outcome2 as a result. Does this mean that I need to separate the "if" statements for string1 and string2 or is there a way of grouping them together to improve readability?

Thanks in advance!

Regards,
KL
You are typing your conditions incorrectly. You must put.
1
2
3
if(input == "string1" || input == "string2")
{
}

1
2
3
if(input == "string1" || "string2")//This is incorrect and will not work as expected. Why? Second condition is always true. 
{
}


== operator works the same on strings, but other operators, like >, < and + do not.
Thank you very much! That's what I get for try to cut corners....
Topic archived. No new replies allowed.