c++字符数字转换(103)

++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
void main()
{
stringstream ss;
//字符串转换成数值
int n;
ss << "325";
ss >> n;
cout << n << endl;
ss.clear();
//数值转换成字符串
string str;
ss << 888;
ss >> str;
cout << str << endl;
ss.clear();
str.empty();
//数值转换成16进制表示的字符串
ss << hex << 255;
ss >> str;
cout << str << endl;
ss.clear();
n = 0;
//16进制表示的字符串转换为数值
ss << "FFA";
ss >> n;
cout << n << endl;
}
// //