codeblocks中报错:'to_string' was not declared in this scope解决方案
阅读原文时间:2023年07月09日阅读:1

在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
#include //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

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章