随笔 - 62  文章 - 96  trackbacks - 0
<2013年1月>
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(7)

随笔分类(66)

随笔档案(62)

文章分类(31)

文章档案(32)

友情链接

最新随笔

积分与排名

  • 积分 - 231225
  • 排名 - 106

最新评论

阅读排行榜

评论排行榜

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 阅读(19201) 评论(3)  编辑 收藏 引用 所属分类: C++之路

FeedBack:
# re: istringstream用法 2011-09-02 12:15 hubing
感谢~  回复  更多评论
  
# re: istringstream用法[未登录] 2012-12-18 19:50 gong
您好,为什么这里的getline(cin, line)中的cin没有定义就直接使用了呢?  回复  更多评论
  
# re: istringstream用法[未登录] 2013-01-22 20:50 mm
@gong
cin是标准输入,在std中已经声明了。  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理