#include <iostream>
#include <cstring>
int main()
{
using namespace std;
const int Size=20;
char word[Size];
int count=0;
cout << "Enter words (to stop,type the word done):/n";
cin >> word;
while (strcmp(word,"done"))
{
++count;
cin >> word;
}
cout << "You entered a total of "<<count<< " words." <<endl;
return 0;
}
Cin字符串输入解析
本文探讨了C++中cin如何处理字符串输入,并通过一个具体示例展示了如何利用cin读取一系列单词直到特定结束条件出现。重点讲解了cin如何识别字符串边界及其实现逻辑。
1万+

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



