当前位置:天才代写 > tutorial > C语言/C++ 教程 > c++ int转换成string范例代码

c++ int转换成string范例代码

2017-11-04 08:00 星期六 所属: C语言/C++ 教程 浏览:355

//第一种要领

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

 

    关键字:

天才代写-代写联系方式