Since you're using std::string
, strcmp
is unnecessary -- you can just use <
, ==
, !=
, etc.
Jerry Coffin
2010-04-23 18:10:18
Since you're using std::string
, strcmp
is unnecessary -- you can just use <
, ==
, !=
, etc.
If you want to use strcmp note that it takes different parameters than the ones you used.
Another way to do this is also
result= strcmp(my_string.c_str(),my_string2.c_str());
Your includes:
Since you are including standard headers, they should be in <>
#include <string>
#include <iostream>
#include with "" is generally used for your own header files, not standard header files.
You are using C++, and therefore need not use strcmp. In C++, you can simply use == & != to compare two strings.
if (my_string == my_string2) result = 0;
else result = 1;
Also, if you want to convert a string to a const char*, you can use mystring.c_str()