首页 > 编程语言 > 详细

C++ 通过ostringstream 实现任意类型转string

时间:2017-10-20 11:35:37      阅读:216      评论:0      收藏:0      [点我收藏+]
#include <iostream>  
#include <string>  
using namespace std;  
int main()  
{  
 int a = 56;  
 double b = 65.123;  
 string str = "";  
 //头文件是sstream  
 std::ostringstream oss;  
 oss << a << "---" << b;  
 str = oss.str();  
 cout << str << endl;  
 return 0;  
}  

输出是56---65.123

 

C++ 通过ostringstream 实现任意类型转string

原文:http://www.cnblogs.com/simplepaul/p/7698410.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!