string类型读取一行字符串,按照空格作为分隔符:
包含头文件<sstream>
string word;
getline(cin,word);
istringstream tmp(word);
while(tmp>>word)
{
...//使用word
}
会跳过所有的空格,while循环的结束条件是字符串tmp到末尾或者末尾全是空格。
不会读入任何一个空格。
包含头文件<sstream>
string word;
getline(cin,word);
istringstream tmp(word);
while(tmp>>word)
{
...//使用word
}
会跳过所有的空格,while循环的结束条件是字符串tmp到末尾或者末尾全是空格。
不会读入任何一个空格。