1、十六进制string转int
//Hexstring 转 int
int HexStringToInt(string str) {
char* end;
int result = static_cast<int>(strtol(str.c_str(), &end, 16));
return result;
}
2、char 转 十六进制string
std::string CharToHex(int i, int width)
{
std::stringstream ioss; //定义字符串流
std::string s_temp; //存放转化后字符
ioss << std::hex << i; //以十六制形式输出
ioss >> s_temp;
string s;
//std::string s(width - s_temp.size(), '0'); //指定位数的需要补0
s += s_temp; //合并
return s;
}
3、int转string
string IntToString(int i){
stringstream ss1;
ss1 << i;
string s = ss1.str();
return s;
}
4、string转char
string s;
s.c_str();
//char类型赋值
//strcpy(result_char, s.c_str());