2016-05-10 185 views
0

我想Cygwin中使用G ++(4.8.1版本)编译下面的代码,它似乎无法使用功能STOD():克++ STOD“在此范围内未声明

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

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

我不断收到这个eroor:

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

,我读了有同样的问题另一个线程。在那里,人们建议使用C++ 11来解决它。所以,我想这两个下面的命令来编译它,但仍然得到了同样的错误:

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

有谁知道解决这个问题呢?

我如何知道C++ 11已启用?我是否需要修改我的代码才能使用它?

非常感谢!

+1

@ 101010'-std = C++ 0x'和'-std = C++ 11'完全一样。 – hvd

+0

@ hvd对不起,不知道。 – 101010

+0

这是一个很好的问题。我完全在linux中拷贝你的代码(ubuntu 16.04和g ++ 5.03),它的工作原理并没有给出任何错误。 –

回答