C++中把int类型变量转化成string类型

来源:互联网 发布:啄木鸟留学 知乎 编辑:程序博客网 时间:2024/05/17 22:17

使用sprintf函数,代码如下:

#include <iostream>#include <string>using namespace std;int main(){    char buf[10];    sprintf(buf, "%d", 12);    string text = buf;    cout << text << endl;    return 0;}
原创粉丝点击