[英]Why is 'stod' still not declared in this scope even after C++11 is enabled and I have included string?
尝试将字符串向量转换为双精度向量时出现错误。 错误不断说:
error: 'stod' was not declared in this scope
即使我为编译器启用了C ++ 11并使用了#include <string>
我也using namespace std;
而且仍然没有用。
代码如下:
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;
using stod;
transform(userNums.begin(), userNums.end(), back_inserter(convUserNums), [](const string & astr){ return stod( astr) ; } ) ;
stod
在namespace std
定义。 您应该像std::stod
这样称呼它。
或using namespace std;
放置using namespace std;
以上。
确保包括必要的标头和using指令。
#include <string>
using std::stod;
int main( const int, const char** )
{
stod( "3.4" );
return EXIT_SUCCESS;
}
请在此处找到std :: stod文档。 请注意,此函数将同时引发 std :: invalid_argument和std :: out_of_range异常。 强烈建议使用try-catch块。
该示例是在gcc version 4.9.2 (Debian 4.9.2-10)
下使用g++ -o main main.cpp -std=c++11
gcc version 4.9.2 (Debian 4.9.2-10)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.