int型转化为std::string

#include <sstream>
#include <string>
using namespace std;


//具体函数有些忘了,不过使用sstream转换数字肯定
//比自己写好一些。因为可以写模板转换float数字。
string int_to_string(int num)
{
sstream<string > ss;
ss << num;

return ss.ToString();
}

//这是模板函数,可能语法上有不正确的地方,你可以查查书籍就可以了,
//重要的不是语法,而是思想。
template<class T>
string num_to_string(T num)
{
sstream<string > ss;
ss << num;

return ss.ToString();

}


strstream ss;
ss << num;
ss >> decInfo;

 


//char a[256];
//sprintf(a,"%d",num);
//decInfo=a;


posted @ 2012-03-29 11:32  笑笑小白  阅读(3498)  评论(0编辑  收藏  举报