Just for completeness, while you should use the built-in string functions when possible, there are common situations where you often have to compare a C-style zero-terminated string with a C ++ string. For example, you will constantly encounter situations when a system call returns a pointer to a C-string.
You can include a C string in a C ++ string and compare them
string s1 = "cat"; string s2 = "dog"; const char *s3 = "lion"; if (s1 == string(s3)) cout << "equal" << endl; else cout << "not equal" << endl;
or compare a C-line under C ++ with another C-line:
a = strcmp(s1.c_str(), s3);
source share