[c++].类型转换

int to string

1.

    int n = 65535;
    char t[256];
    string s;
    //先做到char[]的转换,而后再转为string
    sprintf(t, "%d", n);
    s = t;

2.

    int n = 65535;
    stringstream ss;
    string s;
    ss << n;
    ss >> s;
    cout << s << endl;
    //使用时记得添加头文件 #include<sstream>

你可能感兴趣的:(C++)