Yes you can do it like that. You can also use the built in comparison functions:
1 2 3 4 5 6
string a = "XXX";
if(!a.compare("YYY") // function returns 0 if strings are equal hence the '!'
std::cout << "They are the same.\n";
else
std::cout << "They are not.\n"