c++字符数字转换(103) 发表于 2015-01-09 | 分类于 学习 ++12345678910111213141516171819202122232425262728293031323334#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;}