上一题用string比较简单
#include <iostream>
#include <string>
int main()
{
using namespace std;
string word;
int count=0;
cout << "Enter words (to stop,type the word done):/n";
cin >> word;
while (word!="done")
{
++count;
cin >> word;
}
cout << "You entered a total of "<<count<< " words." <<endl;
return 0;
}
C++字符串计数程序
本文介绍了一个使用C++和string库实现的简单程序,该程序可以统计用户输入的单词数量,直到用户输入done为止。通过这个例子,读者可以了解到如何运用C++中的string类型来处理文本输入。
2927

被折叠的 条评论
为什么被折叠?



