C++ int转string
不论是过去写的这个转换方法,还是今天看到的这个:
string cvt2str( int x )
{
int d = x;
string ans = "";
while( x > 0 )
{
d = x%10;
ans = char(d+'0')+ans;
x /= 10;
}
return ans;
}
转换方法,都不是很好。
我最常用的方法是这样:
#include <sstream>
std::string int2s(int num)
{
std::stringstream ss;
ss<<num;
std::string re;
ss>>re;
return re;
}
转载于//www.cnblogs.com/tiandsp/p/3867937.html
还没有评论,来说两句吧...