首页 > 编程语言 > 详细

C++ int转string

时间:2014-07-25 16:40:51      阅读:392      评论:0      收藏:0      [点我收藏+]

不论是过去写的这个转换方法,还是今天看到的这个:

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;
}

C++ int转string,布布扣,bubuko.com

C++ int转string

原文:http://www.cnblogs.com/tiandsp/p/3867937.html

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