Home

stold

Stold is the C++ standard library function std::stold used to convert a string to a long double value. It is part of the numeric conversion utilities introduced in C++11 and is declared in the <string> header. The function operates within the std namespace and provides overloads for both std::string and std::wstring inputs, with an optional index parameter to report how many characters were processed.

Signature and overloads

- long double stold(const std::string& str, std::size_t* idx = 0);

- long double stold(const std::wstring& str, std::size_t* idx = 0);

The idx parameter, if non-null, is set to the number of characters used in the conversion. There

Behavior and error handling

std::stold throws exceptions to signal errors:

- std::invalid_argument if no conversion could be performed from the input string.

- std::out_of_range if the converted value is outside the representable range of long double.

The conversion is locale-sensitive, so the current locale can influence parsing in terms of decimal separators

Relationship to C equivalents

In C, the analogous conversion function is strtold, which accepts a C string and reports the position

Notes

The actual precision and range of long double depend on the platform and compiler; on some systems

is
no
overload
for
C-style
strings
in
the
C++
std::stold
family;
conversions
from
C
strings
are
typically
done
via
std::strtold
in
C
or
by
first
constructing
a
std::string.
and
numeric
formatting.
of
the
first
unprocessed
character
via
an
endptr.
The
C
and
C++
facilities
share
the
concept
of
converting
textual
representations
to
floating-point
values,
but
std::stold
provides
a
type-safe,
exception-based
C++
interface.
long
double
may
be
the
same
as
double.
As
with
other
std::stof/stod/stold
family
functions,
conversions
can
be
affected
by
locale
settings
and
may
yield
implementation-defined
results
in
edge
cases.