【问题标题】:'stoi' was not declared in this scope after using -std=c++11使用 -std=c++11 后未在此范围内声明“stoi”
【发布时间】:2017-12-01 05:59:08
【问题描述】:

这很可能很奇怪,但是当我收到 stoi 未在此范围内声明的错误时,我笑了,因为我熟悉此错误及其解决方案。

我在 Code Blocks (16.01 , 使用 MinGW) 并尝试重新编译它,但令人惊讶的是它没有工作并且同样的错误仍然存​​在。我尝试重新安装 CodeBlocks,但没有成功。

另外,我尝试使用 windows power shell 和命令提示符 g++ math_handler.cpp -std=c++11,但得到了同样的错误。

我做错了什么?

代码在这里:

#include<string>

using namespace std;

int main()
{
    string body="456";
    int i=stoi(body);
}

注意

  1. 我也尝试过使用 -std=c++0x 和 g++。
  2. to_string() 函数存在同样的问题。
  3. gcc 版本 4.9.2 (tdm -1)

【问题讨论】:

  • 从命令行运行g++ -v。请留意版本号。如果它低于 4.8 c++11 支持是不确定的。还要确保您已包含&lt;string&gt;。除此之外,如果没有看到您的代码,我们将无能为力。
  • 你包含了哪些标题?
  • 等一下!海合会!您可能刚刚运行了 C 编译器。
  • 试试std::stoi
  • @user4581301 gcc 版本 4.9.2

标签: c++ c++11 compiler-errors codeblocks


【解决方案1】:

好的,我发现这是与 CodeBlocks 捆绑在一起的 MinGW 中的一个已知错误。我找到了解决方案here

  1. 下载mingw-to-string-gcc47.zip,其中包含三个补丁 头文件。 (原补丁:wchar.hstdio.hos_defines.h

  2. 从 zip 文件的包含目录中复制 wchar.hstdio.h 到以下目录(覆盖):C:\mingw\include(替换 C:\mingw\ 与相应的目录)

  3. 复制os_defines.h到以下目录(覆盖): C:\mingw\lib\gcc\mingw32\4.7.0\include\c++\mingw32\bits(替换 C:\mingw\ 使用适当的目录)(将 4.7.0 替换为 正确的版本号)

【讨论】:

    【解决方案2】:

    您是否包含了所需的头文件? #include &lt;string&gt;

    stoi 也在 std 命名空间中,所以:

    std::stoi() 
    

    或:

    using namespace std;
    

    【讨论】:

    猜你喜欢
    • 2015-08-20
    • 1970-01-01
    • 1970-01-01
    • 2010-12-17
    • 1970-01-01
    • 2021-07-17
    • 2015-08-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多