hi there, I have a lib function that returns one word of type constchar*. I want to compare this word in an if statement condition against a C++ String word. When I do this the system complains about Incompatible types and undefined behavior. How can I do this?
#include <string>
#include <iostream>
usingnamespace std;
int main ()
{ constchar * str1 = "str1";
const string str2 = "str2";
// Make sure the C++ string is on the leftif (str2 == str1)
cout << "Strings are the same" << endl;
// C method
if (strcmp (str1,str2.c_str()) == 0)
cout << "Strings are the same" << endl;
return 0;
}