MinGW g ++找不到std :: stof

时间:2014-11-07 19:13:43

标签: c++ c++11 mingw

我刚从头开始安装MinGW,使用gcc 4.8.1(最新版本),以下程序无法编译:

#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);
         ^

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

经过一段谷歌搜索后,我确实找到了MinGW的一些旧补丁(4.6 - 4.7),但由于我使用的是gcc 4.8,它们似乎无关紧要。

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

1 个答案:

答案 0 :(得分:1)

不确定确切的问题,但请检查mingw-w64他们现在有gcc 4.9.2。它很好地编译了你的代码。 (但是因为sourceforge.net上的mingw-w64项目正在转向mingw-w64.org,所以最好使用mingw-w64.org

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

可能这应该是评论,而不是答案。