当前位置:首页 >> 编程开发 >> Visual C++ >> 内容

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

时间:2010/6/2 作者:平凡之路 来源:xuhantao.com 浏览:

//第一种方法

#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相关评论
发表我的评论
  • 大名:
  • 内容:
  • 徐汉涛(www.xuhantao.com) © 2024 版权所有 All Rights Reserved.
  • 部分内容来自网络,如有侵权请联系站长尽快处理 站长QQ:965898558(广告及站内业务受理) 网站备案号:蒙ICP备15000590号-1