ostringstream的使用

From: http://blog.csdn.net/liminled/article/details/6645451

在std中还有个ostringstream这么方便的格式化输出的工具
 

  1. std::string generate()  
  2. {  
  3.     ostringstream osm;  
  4.     osm << "xxxx " << 1111;  
  5.       
  6.     // 清空之前的内容  
  7.     osm.str("");  
  8.       
  9.     // 浮点数转换限制  
  10.     double tmp = 123.1234554351236234;  
  11.     osm.precision(15);  
  12.     osm.setf(std::ios::fixed); // 将浮点数的位数限定为小数点之后的位数  
  13.     osm << tmp;   
  14.   
  15.     return osm.str();  
  16. }  

需要包含的头文件:

  1. #include <sstream>   

 

ostringstream作用、主要接口:

  1. Output string stream class  
  2.   
  3. ios_base  ios  ostream  ostringstream   
  4.   
  5. ostringstream provides an interface to manipulate strings as if they were output streams.  
  6.   
  7. The objects of this class maintain internally a pointer to a stringbuf object that can be obtained/modified by calling member rdbuf. This streambuf-derived object controls a sequence of characters (string) that can be obtained/modified by calling member str.  
  8.   
  9.   
  10. Public members  
  11. (constructor) Construct an object and optionally initialize its content (constructor member)   
  12. rdbuf Get/set the associated stringbuf object (public member function)   
  13. str Get/set the associated string object (public member function)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值