This item was added on: 2003/02/19
The following code shows how to convert an int to a C++ string, using a stringstream object:
#include <iostream>
#include <sstream> // Required for stringstreams
#include <string>
std::string IntToString ( int number )
{
std::ostringstream oss;
// Works just like cout
oss<< number;
// Return the underlying string
return oss.str();
}
int main()
{
int number = 12345;
std::string result = IntToString ( number );
// Now we can use concatenation on the number!
std::cout<<"~~{" + result + "}~~\n";
}
Credit: Prelude