• 程设刷题 | 编译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 即可运行。

    【附:一文一图】

  • 相关阅读:
    supervisor使用小记
    linux新增定时脚本
    page_fault_in_nonpaged_area异常解决方案(已解决)
    和安卓对接老是ping不通?试试内网映射
    github文件下载加速器
    mybatis新增账号并且返回主键id
    arraylist源码解析
    MySQL安装教程
    通过get方法的方式获取配置项信息
    @Inject注解
  • 原文地址:https://www.cnblogs.com/zhouie/p/10702603.html
Copyright © 2020-2023  润新知