C++ If String = "x" or "y"

Hello :D

I am making a C++ console app in VS 2008. I am wondering how I can write the command: if string = "x" or "y" {command} else {other command} I tried if (string == "x" || "y") {cout <<"correct";} else {cout << "Incorrect" ;} But that didn't seem to work. Is there another way?

Thanks for any help,

Muhasaresa
Last edited on
Assuming that string is a std::string
1
2
std::string string;
if (string == "x" || string == "y")
If string is a char * you need to use strcmp for the comparison
Thanks! It works now :D
Topic archived. No new replies allowed.