When converting between strings and other numerical kinds, stringstream can be very useful.
Stringstream is comparable to iostream in terms of usage, so learning it is not difficult.
Stringstreams can be used to read strings as well as write data into them.
It mostly works with a string buffer instead of an actual I/O channel.
The stringstream class's fundamental member functions are as follows:
str() is a function that returns the contents of a buffer as a string.
str(string), which changes the buffer's contents to the string argument.
Here's an example of how string streams can be used.
os << "dec: " << 15 << " hex: " << std::hex << 15 << endl;
cout << os.str() << endl;
The result is dec: 15 hex: f.
istringstream is of more or less the same usage.