只用字符串流对各个单词进行操作

​ 使用istringstream对一句话中的各个单词进行操作。需包含头文件#include

1
2
3
4
5
6
7
istringstream iss{s};

for (string word; iss >> word;) {

cout<<word<<endl;

}

定义s=”each word is separated by single space”.则输出为

each

word

is

separated

by

single

space