string类字符串如何比较

将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;

}

发布了4 篇原创文章 · 获赞 0 · 访问量 46

猜你喜欢

转载自blog.csdn.net/tao__f/article/details/104268447