In C ++ 03, use boost::lexical_cast or:
std::stringstream ss(the_string); long double ld; if (ss >> ld) {
In C99, use strtold .
In C89, use sscanf with %Lg .
In C ++ 11, use stold .
There may be subtle differences in exactly which formats each accepts, so check the details first ...
source share