·c++int转换成string类型代码 - 商帝国咨询 - 五略商书

·c++int转换成string类型代码

商帝国咨询头像

阅读 23662 | 分类:文章

//第一种方法

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

int main()
{
    int n = 65535;
    char t[256];
    string s;

    sprintf(t, "%d", n);
    s = t;
    cout << s << endl;

    return 0;
}


    //第二种方法

#include <iostream>
#include <string>
#include <strstream>
using namespace std;

int main()
{
    int n = 65535;
    strstream ss;
    string s;
    ss << n;
    ss >> s;
    cout << s << endl;

    return 0;
}


留言区(共0条)

暂无留言,快来抢占沙发~
作者声明:非原创
平台声明:文章及评论仅代表作者本人观点,五略商书系信息发布平台,仅提供信息存储空间服务,如有侵权,请联系13521509118。转载请注明作者和出处:转自五略商书m.shangdiguo.com,作者商帝国咨询!