Codeblocks编译C++出现to_string is not a member of std 或者 to_string was not declared in this scope的解决方法

来源:互联网 发布:python 中文字符串 编辑:程序博客网 时间:2024/06/07 04:09

原文链接:Enabling string conversion functions in MinGW

C++在将整型、浮点型、长整型等数据类型转换为字符串时,可使用<string>头文件包含的函数:to_string()!

然而在codeblocks等编译环境中,有时候会出现 to_string was not declared in this scope等问题,原因是MINGW编译器不支持to_string()这个方法,这其实可以看成它的一个bug。



解决方法(以codeblocks为例):

1.首先你要使用to_string()这个函数,必须让编译器支持C++11的标准,因为这个函数是C++11提出的。当然不同版本在codeblocks中使用C++11标准,安装及配置方法不尽相同。参考这里提供的安装方法一下面给出两种不同版本下的处理(大体相似,只是去找的位置不同)。

      • 法一:在CodeBlocks > Settings > Global compiler settings > Compiler Flags 中 勾选 Have g++ follow the C++11 ISO C++ language standard,然后点击下方的OK。(如果你的CodeBlocks没找到这个地方,参考下面的方法)

      • 法二点击CodeBlocks > Settings >global compiler settings如图                              至此安装及配置C++11标准完成。

2.下载提供的链接中mingw-to-string-gcc47.zip 这个压缩包。

3.将压缩包解压后,复制wchar.h和stdio.h到你的codeblocks安装路径中的\mingw\include中,将它们替换掉。再将os_defines.h复制到\mingw\lib\gcc\mingw32\4.x.x\include\c++\mingw32\bits即可运行。


【附:一文一图】



阅读全文
0 0