There's no itoa
in the standard, but in C++11 you can use the std::to_string functions.
n C++11 you can use std::to_string
. If this is not available to you, you can use a std::stringstream
:
std::stringstream ss; int x = 23;
ss << x;
std::string str = ss.str();
If this is too verbose, there is boost::lexical_cast. There are some complaints about the performance of lexical_cast
and std::stringstream
, so watch out if this is important to you.
Another option is to use a Boost.Karma, a sublibrary of Spirit. It comes out ahead in most benchmarks.
Usually, itoa
is a bad idea. It is neither part of the C nor C++ standard. You can take some care to identify the platforms that support it and use it conditionally, but why should you, when there are better solutions.