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

时间:2021-09-06 14:48:19

使用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;

}

相关文章