How string class string comparison

The string member function with the c_str () to convert the string * char const
string str1 = "SSD";
string str2 = "sss";
strcmp (str1.c_str (), str2.c_str ());

#include
#include
#include
using namespace std;
int main()
{
string word;
int i = 0;
cout << “Enter words (to stop, type the word done):” << endl;
cin >> word;
for (i; strcmp(word.c_str(), “done”) != 0; i++)
{
cin >> word;

}
cout << "you entered a total of" << i << "  word" << endl;
return 0;

}

Released four original articles · won praise 0 · Views 46

Guess you like

Origin blog.csdn.net/tao__f/article/details/104268447