C ++ How do you modify an integer in a string?

advertisements

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);