错误:'stod'未在此范围中声明 [英] error: 'stod' was not declared in this scope

查看:902
本文介绍了错误:'stod'未在此范围中声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个c ++的项目,我需要将一个字符串转换为双,但我不断收到错误'stod'没有在这个范围内声明。非常感谢您的快速回复。

I'm working on a project for c++ and I need to convert a string to a double but I keep getting the error 'stod' was not declared in this scope. Hasty replies would be greatly appreciated!

#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>

using namespace std;

struct Station
{
string StationID, StationName;
double Elevation, Latitude, Longitude;
int Date, MXPN, MaxTemp, MinTemp, ObsTime;
};

int main()
{
//Initial Variables
ifstream InputFile;
vector<Station> Entry;
string DummyLine, TempLine;
double TempDouble;
int Counter = 0;


InputFile.open("finalc++.csv");
getline(InputFile, DummyLine);
while (InputFile.good())
{
    Entry.push_back(Station());
    getline(InputFile, TempLine);
    stringstream ss (TempLine);
    getline(ss, DummyLine, ',');
    Entry[Counter].StationID = DummyLine;
    getline(ss, DummyLine, ',');
    Entry[Counter].StationName = DummyLine;
    getline(ss, DummyLine, ',');
    Entry[Counter].Elevation = stod(DummyLine);
    Counter++;
}
for (int i = 200; i <= 500; i++)
{
    cout << Entry[i].StationID << endl;
    cout << Entry[i].StationName << endl;
}

    return 0;
}

有没有一些库,我必须包括才能使用它?
btw我在Windows机器x86上使用codeblocks 12.11。

Is there some library that I have to include to be able to use it? btw I'm using codeblocks 12.11 on a windows machine x86.

推荐答案

这是gcc 4.x的已知错误

That's a known bug of the gcc 4.x

启用c ++ 11 stardarts,取决于你的IDE,在CodeBlocks中:
设置,编译器
并检查有g ++遵循c ++ 11 ISO ...
if您正在使用gcc编译器;

Enabling the c++11 stardarts, depend on your IDE, in CodeBlocks go to: settings, compiler and check "have g++ follow the c++11 ISO..." if your are using gcc compiler;

这篇关于错误:'stod'未在此范围中声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆