illegal floating point format on OSx but not Linux

Viewed 107

Using g++ compiler, the code below throws the Illegal floating-point format error on a Macbook pro, but it runs without error on Fedora compiled with both g++ and clang++.

Question: why would it not work on Mac and is there a way to make it work on Mac

#include <iostream>
#include <sstream>

double stringToReal(std::string str) {
   std::istringstream stream(str);
   double value;
   stream >> value >> std::ws;
   if (stream.fail() || !stream.eof()) {
      std::cerr << "stringToReal: Illegal floating-point format (" << str << ")";
   }
   return value;
}

int main() {
    std::cout << stringToReal("1.457460091727E12");
    return 0;
}
1 Answers
Related