istringstream對象可以綁定一行字符串,然后以空格為分隔符把該行分隔開來。
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
string str, line;
while(getline(cin, line))
{
istringstream stream(line);
while(stream>>str)
cout<<str.c_str()<<endl;
}
return 0;
}
測試:
input:
abc? ?df?? e????????????? efgeg????? ffg
ouput:
abc
df
e
efgeg
ffg
posted on 2006-10-17 00:37
beyonlin 閱讀(19292)
評論(3) 編輯 收藏 引用 所屬分類:
C++之路