codeblocks中报错:'to_string' was not declared in this scope解决方案

 在windows下使用codeblocks(编译器采用MinGW)时,有时会遇到“’to_string’ was not declared in this scope”的错误,这里不再对codeblocks、to_string等详细介绍,只介绍跟此问题相关的部分与解决办法。
  首先,to_string是C++11引入的新功能,旧版本编译器可能不支持它,所以要给编译器加上“C++11”编译支持:工具栏打开Settings->Compiler

 

在这里勾选C++11标准即可。
  当然你还要检查你的代码是否有问题。to_string包含在string中,而string包含在空间std中,所以你的代码应该包含头文件和相关空间引入,举个小例子:

#include <iostream>
#include <string> //std::string std::to_string

using namespace std;

int main()
{
    int a = 123;
    cout << "a = " << to_string(a) <<endl; // 如果不加命名空间可以在这里使用std::to_string

    return 0;
}

 如果适用上述方法仍不能解决相关问题,请转至下方链接,还有其他解决方法:

原文链接:https://blog.csdn.net/u013271326/article/details/79613898

原文地址:https://www.cnblogs.com/lx06/p/15726522.html