I'm trying to convert hex to string in C++. Is there any STL function for this?
For example,
int myHex = 0xff00;
string result = someFunc(myHex);
The result should be "0xff00" exactly.
One method I can think of now is to build a map.
typedef map<int, string> hex_to_str_map;
hex_to_string_map myMap {
{0x0, "0"},
{0x1, "1"},
...........
{0xf, "16"},
};
And then convert the hex number one bit by one bit.
I have tried to use ostreamstream
, but this will convert hex to decimal
template <typename T>
string NumberToString (T that) {
ostreamstream ss;
ss << that;
return ss.str()
}
And what I want is to store the converted string to a vector, and use it in another function.