Is this comparison possible to do in C++?
std::string name = "John";
if (name == "Tom")
flag = true;
else
flag = false;
To compare srtings in c++, I recommend you to use STRCMP from:
#include <string.h>
....
STRCMP(name,"Tom"); // This will return 0 if they are equal
so you should use it as:
if (STRCMP(name,"Tom")==0)
flag = true;
else
flag = false;
remember to use #include < string.h>
STRCMP is than the std::basic_string comparision operators?strcmp from C, the call would look different (besides that it is more inefficient and can even lead to wrong results, depending on the contents of name)if(name=="Tom"). And even if it was, this still does not resolve the cases where both lead to different results.
flag = name == "Tom";??flage = (name == "Tom");