不使用C++ 11的整数转字符串

蓝桥杯不支持C++11,那么to_string方法就用不了了。C语言提供了一种方法。

首先需要头文件

#include <sstream>

  然后进行下面的操作就可以,缺点就是比较耗时。

#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;
int main()
{
    int a = 123;
        string s;
        stringstream str;
        str << a;
        s = str.str();
        cout << s;
}   

 参考博客:https://www.cnblogs.com/happygirl-zjj/p/4633789.html

原文地址:https://www.cnblogs.com/wzy-blogs/p/10304695.html