0

I am trying to compile the following code using g++ (version 4.8.1) in cygwin, and it seems that it cannot use the function stod():

//test.cpp
#include<iostream>
#include<vector>
#include<string>
using namespace std;

int main(){
    string a="1.23";
    cout<<stod(a);
    return 0;
}

I keep getting this eroor:

test.cpp:9:14: error: 'stod' was not declared in this scope
  cout<<stod(a);

I read another thread that has the same problem. There, people suggested to use c++11 to address it. So I tried both the following commands to compile it but still got the same error:

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

Does anyone know a solution to this problem?

And how do I know that c++11 is enabled? Do I need to modify my code in order to use it?

Thanks a lot!

mmirror
  • 175
  • 1
  • 3
  • 10

1 Answers1

2

It works in GCC 4.8 on Coliru (http://coliru.stacked-crooked.com/a/8a68ad0ca64c1bff) and also in Clang on my machine. It could be that somehow your Cygwin system doesn't support this function. I suggest you work around it by simply using good old strtod() instead. That's probably what stod() uses under the hood anyway.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436