-1

I just (re)installed MinGW from scratch, with gcc 4.8.1 (the latest available), and the following program won't compile:

#include <iostream>
#include <string>

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

Here's the command I use:

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

I get this error:

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

The file bits\basic_string.h which declares std::stof is included properly in the string header, and I checked bits\basic_string.h for std::stof's declaration, and it's there.

After a bit of Googling I did find some old patches for MinGW (4.6 - 4.7) but they seem irrelevant since I'm on gcc 4.8.

Any ideas? Thanks in advance.

Archimaredes
  • 1,397
  • 12
  • 26
  • https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52015#c25 – n. m. could be an AI Nov 07 '14 at 19:21
  • possible duplicate of [Problems with std::stoi, not working on MinGW GCC 4.7.2](http://stackoverflow.com/questions/16132176/problems-with-stdstoi-not-working-on-mingw-gcc-4-7-2) See [Conduit's](https://stackoverflow.com/questions/16132176/problems-with-stdstoi-not-working-on-mingw-gcc-4-7-2/16132279#comment40489980_16132279) comment. –  Nov 07 '14 at 19:23

1 Answers1

1

Not sure about exact problem, but check mingw-w64 they have gcc 4.9.2 for now. It compiles your code just well. (But since the mingw-w64 project on sourceforge.net is moving to mingw-w64.org it's better to use mingw-w64.org)

Despite of it's name it provides compilers for both x86 and x64 targets.

Probably this should be a comment, not an answer.

POQDavid
  • 195
  • 1
  • 15
Ivan Aksamentov - Drop
  • 12,860
  • 3
  • 34
  • 61
  • 2
    Stephan T. Lavavej's 64-bit MinGW distro is also a [good alternative](http://nuwen.net/mingw.html). –  Nov 07 '14 at 19:26
  • @remyabel Cool! Never knew he has it on his page. The most interesting stuff is that his MinGW is also bundled with boost and some other popular libs. – Ivan Aksamentov - Drop Nov 07 '14 at 19:37