c++中int转string的有哪些方法
在C++中,可使用以下几种方法将int转换为string:
int num = 123;
std::string str = std::to_string(num);#include
int num = 123;
std::stringstream ss;
ss << num;
std::string str = ss.str(); #include
int num = 123;
char buf[10];
std::sprintf(buf, "%d", num);
std::string str(buf); 以上是三种经常使用的将int转换为string的方法,根据实际情况选择合适的方法便可。
TOP