将string的成员函数用c_str()把string转换为const char *
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;
}