设计一个检查字串内重复单词的程序
#include<iostream>
using namespace std;
int main() {
string previous = " ";
string current;
//cin >> current;//输入the cat cat jump
//cout << current;//cout结果是只有the,说明current只储存了the但以下代码却能识别cat
while (cin>>current)
{
if (previous == current)
cout << "repeated word:" << current << "\n";
previous = current;
}
}
运行输入 the cat cat jump,能正常识别重复单词是cat
我的疑问是:
运行到 while(cin>>current)时,
由于输入字串存在空格字符,
不应该是current只读取到the,后面的cat cat jump均无法被存储在current内吗?
为什么while函数还是能进行cat 与cat对比