String function

for a const char*, we could use stricmp() this function to compare two variable . What kinds of function I can use for c++ std::string to compare string variable?
Thanks
 
 if(stricmp(list[i].ID, p->ID ==0)
Use ==
1
2
3
4
std::string a = "apple";
std::string b = "apple";

std::cout << ((a == b) ? "same" : "different") << std::endl;
Last edited on
thanks for your ans.

how about returning bool value, 0 or 1 , just like what stricmp do?
operator== does return bool.

strcmp does not return bool. It returns -1, 0 or 1.

You'll find this helpful. http://en.cppreference.com/w/cpp/string/basic_string/operator_cmp

operator== calls the string trait compare function to do the actual comparison, allowing you to provide some degree of customisation.
std::string::compare does that, but you're now in C++ land, so try and stick with == like kbw said.
thx both
Topic archived. No new replies allowed.