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

#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

 

posted @ 2017-10-20 11:00  爱简单的Paul  阅读(4287)  评论(0编辑  收藏  举报