字符串转10进制整数、16进制整数和整形转换成字符串
string to int
const std::string& hexDigit = "0x100"; //如果直接使用stoi转换值是0
const std::string& decDigit = "100";
auto hexValue = stoi(hexDigit, nullptr, 16);
auto decValue = stoi(decDigit);
#include <sstream>
int to string
const int hexValue = 0x100;
std::to_string(hexValue); //输出字符串是"256"
如果我们想字符串也是"0x100"可以使用下面两种方法
std::ostringstream os;
os<<std::hex<<hexValue;
std::string hexDigitString(os.str());
c风格转换
#include <cstdio>
char hexDigits[128]{0};
snprintf(hexDigits, 128, "%x",hexValue);