dila
New member
This is really simple, and most people would recommend boost::lexical_cast for this purpose, which is nice if you have boost (apart from the mess of handling the exceptions), but if you just have straight c++ you can still do it without any special utility routines like this:
You can see that the str() method of the std::stringstream object just returns you an std::string.
Happy coding
Code:
#include <iostream>
#include <sstream>
int main()
{
int x = 12345;
std::stringstream y;
y << "The number is: " << x;
std::cout << y.str() << std::endl;
return 0;
}
You can see that the str() method of the std::stringstream object just returns you an std::string.
Happy coding