最近從windows 移植程序的時候發現to_string()函數在linux 中不能用,網上找了幾種方法,覺得使用stringstream對象來實現類型轉化比較好一點。
你只需在你工程中加入下面的to_sting()函數,就不需要修改你原程序了。(這篇只是本人移植工程時的心得,高手繞過!)
/*
* to_string.cpp
* Created on: 2014年9月11日
* Author: tursunjan
* linux int to string
*/
#include<iostream>
#include<sstream>
using namespace std;
string to_string(int a)
{
ostringstream ostr;
ostr << a;
string astr = ostr.str();
//cout << astr <<endl;
return astr ;
}
int main()
{
int testNum=10;
cout<<to_string(testNum)<<endl;
return 0;
}