在C++中,可以使用以下几种方法将int转换为string:
int num = 123;
std::string str = std::to_string(num);
#include <sstream>
int num = 123;
std::stringstream ss;
ss << num;
std::string str = ss.str();
#include <cstdio>
int num = 123;
char buf[10];
std::sprintf(buf, "%d", num);
std::string str(buf);
以上是三种常用的将int转换为string的方法,根据实际情况选择适合的方法即可。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:c++中string转int的方法是什么