Elipse cannot build C++ programs on my system if they contains calls to string's function stod(). I am running Ubuntu 14.04 with Eclipse using the C/C++ perspective.
I have included the header, and compiled with the -std=c++11 compile flag and set the compiler from gcc to g++, but it did not work. I also tried using Eclipse's "ISO C++11" dialect setting (which sets the compile flag to -std=c++0x. In all cases, the compiler is unable to see the stod function.
To isolate the problem, I compiled the example from the cplusplus.com website for stod:
// stod example
#include <iostream> // std::cout
#include <string> // std::string, std::stod
int main ()
{
std::string orbits ("365.24 29.53");
std::string::size_type sz; // alias of size_t
double earth = std::stod (orbits,&sz);
double moon = std::stod (orbits.substr(sz));
std::cout << "The moon completes " << (earth/moon) << " orbits per Earth year.\n";
return 0;
}
This fails to compile, with the error "Function stod could not be resolved". If I remove those calls, and initialize earth to 0.0, and moon to 1.0, it compiles and runs fine (with the wrong answer of course).
I tried compiling the same program from the Ubuntu command line and it works when I include the -std=c++11 compile flag.
> g++ -o teststod teststod.cpp -std=c++11
> teststod
The moon completes 12.3684 orbits per Earth year.
My Linux is up to date, and I have done an apt-get update to be sure. One possible clue, I originally installed Eclipse with only the Java target, but I created these projects in Eclipse as C++ projects with C/C++ perspectives.
For reference, here is what Eclipse's About page returns:
IDE for Java Developers
Version: Mars.1 Release (4.5.1)
Build id: 20150924-1200
Ubuntu version:
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty