0
I need some help regarding logical 'or' operator, if-else conditions and strings.
First read my following program :- #include <iostream> using namespace std; int main () { string a,b = "Hi user"; cin>>a; if (a == "Hello"){ cout<<b; } else if(a == "Hey"){ cout<<b; } return 0; } It's just an example of some code I've been doing and it worked well ,but I just want to make it more compact and reliable in case of more conditional strings,so I did the following :- if(a == "Hey" || "Hello"){ cout<<b; } But unfortunately, it didn't worked. Please help me out in this.
4 Respostas
+ 22
if (a == "Hey"||a == "Hello") {
cout<<b;
}
+ 2
unfortunately Your method is not supported - some days i had the sam problem.
other tip is to use a regullar expressions (if exiats like in java)
i'm condused why a==(x||y) not works...
+ 1
Thank you ValentinHacker. It worked smoothly :)
0
have you tried dipping it in rice?