char c = 120; string s0 = format("{:6}", 42); // value of s0 is " 42" string s1 = format("{:6}", 'x'); // value of s1 is "x " string s2 = format("{:*<6}", 'x'); // value of s2 is "x*****" string s3 = format("{:*>6}", 'x'); // value of s3 is "*****x" string s4 = format("{:*^6}", 'x'); // value of s4 is "**x***" string s5 = format("{:6d}", c); // value of s5 is " 120" string s6 = format("{:6}", true); // value of s6 is "true "— end example
Option | Meaning |
< | Forces the field to be aligned to the start of the available space. This is the default for
non-arithmetic types, charT, and bool,
unless an integer presentation type is specified. |
> | Forces the field to be aligned to the end of the available space. This is the default for
arithmetic types other than charT and bool
or when an integer presentation type is specified. |
^ | Forces the field to be centered within the available space
by inserting
characters before and
characters after the value, where
n is the total number of fill characters to insert. |
Option | Meaning |
+ | Indicates that a sign should be used for both non-negative and negative
numbers. The + sign is inserted before the output of to_chars for
non-negative numbers other than negative zero. |
- | Indicates that a sign should be used for
negative numbers and negative zero only (this is the default behavior). |
space | Indicates that a leading space should be used for
non-negative numbers other than negative zero, and
a minus sign for negative numbers and negative zero. |
double inf = numeric_limits<double>::infinity(); double nan = numeric_limits<double>::quiet_NaN(); string s0 = format("{0:},{0:+},{0:-},{0: }", 1); // value of s0 is "1,+1,1, 1" string s1 = format("{0:},{0:+},{0:-},{0: }", -1); // value of s1 is "-1,-1,-1,-1" string s2 = format("{0:},{0:+},{0:-},{0: }", inf); // value of s2 is "inf,+inf,inf, inf" string s3 = format("{0:},{0:+},{0:-},{0: }", nan); // value of s3 is "nan,+nan,nan, nan"— end example
char c = 120; string s1 = format("{:+06d}", c); // value of s1 is "+00120" string s2 = format("{:#06x}", 0xa); // value of s2 is "0x000a" string s3 = format("{:<06}", -42); // value of s3 is "-42 " (0 is ignored because of < alignment)— end example
string s0 = format("{}", 42); // value of s0 is "42" string s1 = format("{0:b} {0:d} {0:o} {0:x}", 42); // value of s1 is "101010 42 52 2a" string s2 = format("{0:#x} {0:#X}", 42); // value of s2 is "0x2a 0X2A" string s3 = format("{:L}", 1234); // value of s3 might be "1,234" // (depending on the locale)— end example
Type | Meaning |
a | If precision is specified, equivalent to
to_chars(first, last, value, chars_format::hex, precision)where precision is the specified formatting precision; equivalent to to_chars(first, last, value, chars_format::hex)otherwise. |
A | The same as a, except that
it uses uppercase letters for digits above 9 and
P to indicate the exponent. |
e | Equivalent to
to_chars(first, last, value, chars_format::scientific, precision)where precision is the specified formatting precision, or 6 if precision is not specified. |
E | |
f, F | Equivalent to
to_chars(first, last, value, chars_format::fixed, precision)where precision is the specified formatting precision, or 6 if precision is not specified. |
g | Equivalent to
to_chars(first, last, value, chars_format::general, precision)where precision is the specified formatting precision, or 6 if precision is not specified. |
G | |
none | If precision is specified, equivalent to
to_chars(first, last, value, chars_format::general, precision)where precision is the specified formatting precision; equivalent to to_chars(first, last, value)otherwise. |