long double stold (const string& str, size_t* idx = 0);
long double stold (const wstring& str, size_t* idx = 0);
Convert string to long double
Parses str interpreting its content as a floating-point number, which is returned as a value of type long double.
If idx is not a null pointer, the function also sets the value of idx to the position of the first character in str after the number.
The function uses strtold (or wcstold) to perform the conversion (see strtod for more details on the process).
- String object with the representation of a floating-point number.
- Pointer to an object of type size_t, whose value is set by the function to position of the next character in str after the numerical value.
This parameter can also be a null pointer, in which case it is not used.
On success, the function returns the converted floating-point number as a value of type long double.
// stold example
#include <iostream> // std::cout
#include <string> // std::string, std::stod
int main ()
std::string orbits ("90613.305 365.24");
std::string::size_type sz; // alias of size_t
long double pluto = std::stod (orbits,&sz);
long double earth = std::stod (orbits.substr(sz));
std::cout << "Pluto takes " << (pluto/earth) << " years to complete an orbit.\n";
Pluto takes 248.093 years to complete an orbit.
Unspecified, but generally linear in the number of characters interpreted.
Modifies the value pointed by idx (if not zero).
If no conversion could be performed, an invalid_argument exception is thrown.
If the value read is out of the range of representable values by a long double (in some library implementations, this includes underflows), an out_of_range exception is thrown.
An invalid idx causes undefined behavior.
- Convert string to float (function template
- Convert string to double (function template
- Convert string to integer (function template
- Convert string to long double (function