方法:先借助sprintf函数将int转换为char类型的数组,然后char*可以转换为string
代码如下:
#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;
}
方法:先借助sprintf函数将int转换为char类型的数组,然后char*可以转换为string
代码如下:
#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;
}