while(cin>>word)工作步骤是:从输入流中读取,以空格为分隔保存到word里面。具体来说就是输入yyy hhh对while循环来说就是执行了两次,第一次遇到空格结束,接着第二次从空格后面开始读(不管有多少个空格都是从实际字符开始)。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string word;
while(cin>>word){
for(auto a :word)
cout << a << " ";
cout<<endl;
}
return 0;
}
运行结果: