MinGW g++ cannot find std::stof



我刚刚用gcc 4.8.1(最新版本)从头开始(重新)安装了MinGW,下面的程序不会编译:

#include <iostream>
#include <string>
int main()
{
    float f;
    std::string s = "5.235";
    f = std::stof(s);
    std::cout << f << 'n';
}

这是我使用的命令:

g++ -std=c++11 -o test test.cpp

我得到这个错误:

test.cpp:8:9: error: 'stof' is not a member of 'std'
     f = std::stof(s);
         ^

声明std::stof的文件bitsbasic_string.h正确地包含在string头中,我检查了bitsbasic_string.h中std::stof的声明,它就在那里。

在谷歌上搜索了一下之后,我确实找到了一些MinGW(4.6-4.7)的旧补丁,但它们似乎无关紧要,因为我使用的是gcc 4.8。

有什么想法吗?提前谢谢。

不确定确切的问题,但请检查mingw-w64他们现在有gcc 4.9.2。它能很好地编译您的代码。(但由于sourceforge.net上的mingw-w64项目正在转移到mingw-w64.org,因此最好使用mingw-w64.org)

尽管它的名字,它提供了x86和x64目标的编译器。

也许这应该是一个评论,而不是一个答案

最新更新