正文

string流2006-08-17 20:51:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/argol/17646.html

分享到:

  ostringstream类向一个string插入字符,istringstream类从一个string对象读取字符,而stringstream类可以用来支持读和写两种操作。为了使用string流,我们必须包含相关的头文件:  #include <sstream>  例如,  string read_file_into_string()  {     ifstream ifile( "alice_emma" );     ostringstream buf;     char ch;          while(buf && ifile.get( ch ))        buf.put( ch );     return buf.str();  }  成员函数str()返回与ostringstream类对象相关联的string对象。    istringstream由一个string对象构造而来,它可以读取该string对象。istringstream的一种用法是将数值字符串转换成算术值。      ---摘抄自《C++PRIME》.

阅读(4935) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册