第一种:
int a = 10;
char *intStr = itoa(a);
string str = string(intStr);
第二种:
int a = 10;
stringstream ss;
ss << a;
string str = ss.str();
第三种:(C++11 ,部分编译器不支持)
std::string s = std::to_string(42);
第四种:
#include <sstream>
#define SSTR( x ) static_cast< std::ostringstream & >( \
( std::ostringstream() << std::dec << x ) ).str()
第五种:
#include <boost/lexical_cast.hpp>
int num = 4;
std::string str = boost::lexical_cast<std::string>(num);