1

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;
}

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.

user3073174
  • 29
  • 1
  • 5
  • You need to enable C++11 – billz Dec 07 '13 at 05:30
  • compiles fine with visual c++ 12.0, gives the cited error with mingw g++ 4.7.2. possibly you can upgrade to later version of g++ (i don't know what's bundled with codeblocks 12.11, or whether later version of g++ fixes this). or simply implement your own conversion function, e.g. based on [strtod](http://en.cppreference.com/w/cpp/string/byte/strtof). – Cheers and hth. - Alf Dec 07 '13 at 05:30
  • I'm new to coding so I have no idea how to do any of this. Any idea how to enable c++11? – user3073174 Dec 07 '13 at 05:39
  • http://stackoverflow.com/questions/6528595/how-can-i-get-codeblocks-to-compile-with-std-c0x-with-gcc – John Zwinck Dec 07 '13 at 05:42

1 Answers1

2

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

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;