方法一:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#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; } |
方法二:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
//第二种方法 #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; } |