zoukankan      html  css  js  c++  java
  • 程设刷题 | 编译C++文件出现to_string is not a member of std 或者 to_string was not declared in this scope的解决方法

    写在前面

    原文链接Enabling string conversion functions in MinGW

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

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

    解决方法(以Codeblocks为例)

    • 首先你要使用to_string()这个函数,必须让编译器支持C++11的标准,因为这个函数是C++11提出的。当然不同版本在codeblocks中使用C++11标准,安装及配置方法不尽相同。
    • 【参考这里提供的安装方法一】下面给出两种不同版本下的处理(大体相似,只是去找的位置不同)。
    1. 法一:CodeBlocks > Settings > Global compiler settings > Compiler Flags 中 勾选 Have g++ follow the C++11 ISO C++ language standard,然后点击下方的OK。(如果你的CodeBlocks没找到这个地方,参考下面的方法)
    2. 法二点击CodeBlocks > Settings >global compiler settings如图  

    • 至此安装及配置C++11标准完成。
    • 下载提供的链接中 mingw-to-string-gcc47.zip 这个压缩包。
    • 将压缩包解压后,复制 wchar.h 和 stdio.h 到你的Codeblocks安装路径中的 mingwinclude 中,将它们替换掉。再将 os_defines.h 复制到 mingwlibgccmingw324.x.xincludec++mingw32its 即可运行。

    【附:一文一图】

  • 相关阅读:
    回家第二周
    回文
    回家第一周
    回家第四周
    《大道至简》读后感
    第三周Java课后题
    Java小测代码及截图
    【CheckBox】选择或取消所有CheckBox
    Web Developer's Handbook
    Oracle PL/SQL
  • 原文地址:https://www.cnblogs.com/zhouie/p/10702603.html
Copyright © 2011-2022 走看看