Possible Duplicate:
Alternative to itoa() for converting integer to string C++?
How do you change an integer to a string in c++?
Possible Duplicate:
Alternative to itoa() for converting integer to string C++?
How do you change an integer to a string in c++?
Standard C++ library style:
#include <sstream>
#include <string>
(...)
int number = 5;
std::stringstream ss;
ss << number;
std::string numberAsString(ss.str());
Or if you're lucky enough to be using C++11:
#include <string>
(...)
int number = 5;
std::string numberAsString = std::to_string(number);
You could use snprintf(char *str, size_t size, const char *format, ...)
to get a char[], then use string(char*)
get string.
Of course,there're other ways.