views:

156

answers:

4
+2  Q: 

string Comparison

+4  A: 

Since you're using std::string, strcmp is unnecessary -- you can just use <, ==, !=, etc.

Jerry Coffin
A: 

If you want to use strcmp note that it takes different parameters than the ones you used.

http://www.cppreference.com/wiki/c/string/strcmp

Cristina
A: 

Another way to do this is also

result= strcmp(my_string.c_str(),my_string2.c_str());
Romain Hippeau
+3  A: 

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()

Sagar
To be more pedantic, the `strcmp` function applies to an array of characters terminated by a null (a.k.a. char *). If you really need to use `strcmp`, then use it with the `c_str()` method of `std::string`.
Thomas Matthews
True, should have clarified that. Thanks!
Sagar
Thanks ALL OV You