#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;
}
#include <strstream>
strstream ss;
换成
#include <sstream>
stringstream ss;
#include "iostream"
#include "string"
using namespace std;
string int2str(int n) {
char t[24];
int i = 0;
while (n) {
t[i++] = (n % 10) + '0';
n /= 10;
}
t[i] = 0;
return string(strrev(t));
}
int main() {
int n = 1312355;
string str = int2str(n);
cout<<str<<endl;
return 0;
}
int转换成string类型
最新推荐文章于 2022-04-15 10:57:30 发布