Cygwin not compiling stod

2020-04-18 03:28发布

问题:

I'm trying to compile this example code

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

Trying to compile from the command prompt gives

C:\Users\DWane\Documents>g++ -std=c++0x testme.cpp -o out.exe
testme.cpp: In function 'int main()':
testme.cpp:9:18: error: 'stod' is not a member of 'std'
   double earth = std::stod (orbits,&sz);
                  ^
testme.cpp:10:17: error: 'stod' is not a member of 'std'
   double moon = std::stod (orbits.substr(sz));
                 ^

I'm running Windows 8 64bit and have g++ (GCC) 4.8.3.

回答1:

The short answer is that it's a bug within Cygwin's port of GCC (or libstdc++). The only message I can find on the Cygwin mailing list is from Jan 29, 2014 and it merely says:

Did you try the suggestion for the same problem under mingw? It looks like this could be a temporary workaround until the problem is fixed. Just make

sure you try it on /lib/gcc/i686-pc-cygwin/4.8.2/include/c++/bits/basic_string.h if you're building for Cygwin..

MinGW has been known to have issues with string conversion functions as well, even though it's different from Cygwin. My suggestion is to download Stephan T. Lavavej's 64-bit MinGW distribution which comes with GCC 4.9.1 and many up to date packages.



标签: c++ c++11 cygwin