23 General utilities library [utilities]
All functions named
to_chars
convert
value into a character string
by successively filling the range
[first, last),
where
[first, last) is required to be a valid range
. If the member
ec
of the return value
is such that the value,
when converted to
bool,
is
false,
the conversion was successful
and the member
ptr
is the one-past-the-end pointer of the characters written
. Otherwise,
the member
ec has the value
errc::value_too_large,
the member
ptr has the value
last,
and the contents of the range
[first, last) are unspecified
.The functions that take a floating-point
value
but not a
precision parameter
ensure that the string representation
consists of the smallest number of characters
such that
there is at least one digit before the radix point (if present) and
parsing the representation using the corresponding
from_chars function
recovers
value exactly
. [
Note: This guarantee applies only if
to_chars and
from_chars
are executed on the same implementation
. —
end note ]
The functions taking a
chars_format parameter
determine the conversion specifier for
printf as follows:
The conversion specifier is
f if
fmt is
chars_format::fixed,
e if
fmt is
chars_format::scientific,
a (without leading
"0x" in the result)
if
fmt is
chars_format::hex,
and
g if
fmt is
chars_format::general. to_chars_result to_chars(char* first, char* last, see below value, int base = 10);
Requires: base has a value between 2 and 36 (inclusive)
. Effects: The value of
value is converted
to a string of digits in the given base
(with no redundant leading zeroes)
. 35 (inclusive)
are represented as lowercase characters
a. If
value is less than zero,
the representation starts with a minus sign
.Remarks:
The implementation shall provide overloads
for all signed and unsigned integer types
and
char
as the type of the parameter
value. to_chars_result to_chars(char* first, char* last, float value);
to_chars_result to_chars(char* first, char* last, double value);
to_chars_result to_chars(char* first, char* last, long double value);
Effects: value is converted to a string
in the style of
printf
in the
"C" locale
. The conversion specifier is
f or
e,
chosen according to the requirement for a shortest representation
(see above);
a tie is resolved in favor of
f.to_chars_result to_chars(char* first, char* last, float value, chars_format fmt);
to_chars_result to_chars(char* first, char* last, double value, chars_format fmt);
to_chars_result to_chars(char* first, char* last, long double value, chars_format fmt);
Requires: fmt has the value of
one of the enumerators of
chars_format. Effects: value is converted to a string
in the style of
printf
in the
"C" locale
. to_chars_result to_chars(char* first, char* last, float value,
chars_format fmt, int precision);
to_chars_result to_chars(char* first, char* last, double value,
chars_format fmt, int precision);
to_chars_result to_chars(char* first, char* last, long double value,
chars_format fmt, int precision);
Requires: fmt has the value of
one of the enumerators of
chars_format. Effects: value is converted to a string
in the style of
printf
in the
"C" locale
with the given precision
.