| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
1 |
# Format String Syntax |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
2 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
3 |
Formatting functions such as [`fmt::format`](api.md#format) and [`fmt::print`]( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
4 |
api.md#print) use the same format string syntax described in this section. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
5 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
6 |
Format strings contain "replacement fields" surrounded by curly braces `{}`. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
7 |
Anything that is not contained in braces is considered literal text, which is |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
8 |
copied unchanged to the output. If you need to include a brace character in |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
9 |
the literal text, it can be escaped by doubling: `{{` and `}}`. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
10 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
11 |
The grammar for a replacement field is as follows: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
12 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
13 |
<a id="replacement-field"></a> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
14 |
<pre><code class="language-json" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
15 |
>replacement_field ::= "{" [arg_id] [":" (<a href="#format-spec" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
16 |
>format_spec</a> | <a href="#chrono-format-spec">chrono_format_spec</a>)] "}" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
17 |
arg_id ::= integer | identifier |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
18 |
integer ::= digit+ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
19 |
digit ::= "0"..."9" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
20 |
identifier ::= id_start id_continue* |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
21 |
id_start ::= "a"..."z" | "A"..."Z" | "_" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
22 |
id_continue ::= id_start | digit</code> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
23 |
</pre> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
24 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
25 |
In less formal terms, the replacement field can start with an *arg_id* that |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
26 |
specifies the argument whose value is to be formatted and inserted into the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
27 |
output instead of the replacement field. The *arg_id* is optionally followed |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
28 |
by a *format_spec*, which is preceded by a colon `':'`. These specify a |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
29 |
non-default format for the replacement value. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
30 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
31 |
See also the [Format Specification |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
32 |
Mini-Language](#format-specification-mini-language) section. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
33 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
34 |
If the numerical arg_ids in a format string are 0, 1, 2, ... in sequence, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
35 |
they can all be omitted (not just some) and the numbers 0, 1, 2, ... will be |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
36 |
automatically inserted in that order. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
37 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
38 |
Named arguments can be referred to by their names or indices. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
39 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
40 |
Some simple format string examples: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
41 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
42 |
```c++ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
43 |
"First, thou shalt count to {0}" // References the first argument |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
44 |
"Bring me a {}" // Implicitly references the first argument |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
45 |
"From {} to {}" // Same as "From {0} to {1}" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
46 |
``` |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
47 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
48 |
The *format_spec* field contains a specification of how the value should |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
49 |
be presented, including such details as field width, alignment, padding, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
50 |
decimal precision and so on. Each value type can define its own |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
51 |
"formatting mini-language" or interpretation of the *format_spec*. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
52 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
53 |
Most built-in types support a common formatting mini-language, which is |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
54 |
described in the next section. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
55 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
56 |
A *format_spec* field can also include nested replacement fields in |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
57 |
certain positions within it. These nested replacement fields can contain |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
58 |
only an argument id; format specifications are not allowed. This allows |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
59 |
the formatting of a value to be dynamically specified. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
60 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
61 |
See the [Format Examples](#format-examples) section for some examples. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
62 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
63 |
## Format Specification Mini-Language |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
64 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
65 |
"Format specifications" are used within replacement fields contained within a |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
66 |
format string to define how individual values are presented. Each formattable |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
67 |
type may define how the format specification is to be interpreted. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
68 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
69 |
Most built-in types implement the following options for format |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
70 |
specifications, although some of the formatting options are only |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
71 |
supported by the numeric types. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
72 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
73 |
The general form of a *standard format specifier* is: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
74 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
75 |
<a id="format-spec"></a> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
76 |
<pre><code class="language-json" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
77 |
>format_spec ::= [[fill]align][sign]["#"]["0"][width]["." precision]["L"][type] |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
78 |
fill ::= <a character other than '{' or '}'> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
79 |
align ::= "<" | ">" | "^" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
80 |
sign ::= "+" | "-" | " " |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
81 |
width ::= <a href="#replacement-field">integer</a> | "{" [<a |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
82 |
href="#replacement-field">arg_id</a>] "}" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
83 |
precision ::= <a href="#replacement-field">integer</a> | "{" [<a |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
84 |
href="#replacement-field">arg_id</a>] "}" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
85 |
type ::= "a" | "A" | "b" | "B" | "c" | "d" | "e" | "E" | "f" | "F" | |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
86 |
"g" | "G" | "o" | "p" | "s" | "x" | "X" | "?"</code> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
87 |
</pre> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
88 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
89 |
The *fill* character can be any Unicode code point other than `'{'` or `'}'`. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
90 |
The presence of a fill character is signaled by the character following it, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
91 |
which must be one of the alignment options. If the second character of |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
92 |
*format_spec* is not a valid alignment option, then it is assumed that both |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
93 |
the fill character and the alignment option are absent. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
94 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
95 |
The meaning of the various alignment options is as follows: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
96 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
97 |
<table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
98 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
99 |
<th>Option</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
100 |
<th>Meaning</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
101 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
102 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
103 |
<td><code>'<'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
104 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
105 |
Forces the field to be left-aligned within the available space (this is the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
106 |
default for most objects). |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
107 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
108 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
109 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
110 |
<td><code>'>'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
111 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
112 |
Forces the field to be right-aligned within the available space (this is |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
113 |
the default for numbers). |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
114 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
115 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
116 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
117 |
<td><code>'^'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
118 |
<td>Forces the field to be centered within the available space.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
119 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
120 |
</table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
121 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
122 |
Note that unless a minimum field width is defined, the field width will |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
123 |
always be the same size as the data to fill it, so that the alignment |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
124 |
option has no meaning in this case. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
125 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
126 |
The *sign* option is only valid for floating point and signed integer types, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
127 |
and can be one of the following: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
128 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
129 |
<table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
130 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
131 |
<th>Option</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
132 |
<th>Meaning</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
133 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
134 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
135 |
<td><code>'+'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
136 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
137 |
Indicates that a sign should be used for both nonnegative as well as |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
138 |
negative numbers. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
139 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
140 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
141 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
142 |
<td><code>'-'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
143 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
144 |
Indicates that a sign should be used only for negative numbers (this is the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
145 |
default behavior). |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
146 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
147 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
148 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
149 |
<td>space</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
150 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
151 |
Indicates that a leading space should be used on nonnegative numbers, and a |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
152 |
minus sign on negative numbers. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
153 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
154 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
155 |
</table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
156 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
157 |
The `'#'` option causes the "alternate form" to be used for the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
158 |
conversion. The alternate form is defined differently for different |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
159 |
types. This option is only valid for integer and floating-point types. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
160 |
For integers, when binary, octal, or hexadecimal output is used, this |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
161 |
option adds the prefix respective `"0b"` (`"0B"`), `"0"`, or `"0x"` |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
162 |
(`"0X"`) to the output value. Whether the prefix is lower-case or |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
163 |
upper-case is determined by the case of the type specifier, for example, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
164 |
the prefix `"0x"` is used for the type `'x'` and `"0X"` is used for |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
165 |
`'X'`. For floating-point numbers the alternate form causes the result |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
166 |
of the conversion to always contain a decimal-point character, even if |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
167 |
no digits follow it. Normally, a decimal-point character appears in the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
168 |
result of these conversions only if a digit follows it. In addition, for |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
169 |
`'g'` and `'G'` conversions, trailing zeros are not removed from the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
170 |
result. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
171 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
172 |
*width* is a decimal integer defining the minimum field width. If not |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
173 |
specified, then the field width will be determined by the content. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
174 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
175 |
Preceding the *width* field by a zero (`'0'`) character enables |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
176 |
sign-aware zero-padding for numeric types. It forces the padding to be |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
177 |
placed after the sign or base (if any) but before the digits. This is |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
178 |
used for printing fields in the form "+000000120". This option is only |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
179 |
valid for numeric types and it has no effect on formatting of infinity |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
180 |
and NaN. This option is ignored when any alignment specifier is present. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
181 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
182 |
The *precision* is a decimal number indicating how many digits should be |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
183 |
displayed after the decimal point for a floating-point value formatted |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
184 |
with `'f'` and `'F'`, or before and after the decimal point for a |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
185 |
floating-point value formatted with `'g'` or `'G'`. For non-number types |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
186 |
the field indicates the maximum field size - in other words, how many |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
187 |
characters will be used from the field content. The *precision* is not |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
188 |
allowed for integer, character, Boolean, and pointer values. Note that a |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
189 |
C string must be null-terminated even if precision is specified. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
190 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
191 |
The `'L'` option uses the current locale setting to insert the appropriate |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
192 |
number separator characters. This option is only valid for numeric types. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
193 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
194 |
Finally, the *type* determines how the data should be presented. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
195 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
196 |
The available string presentation types are: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
197 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
198 |
<table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
199 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
200 |
<th>Type</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
201 |
<th>Meaning</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
202 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
203 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
204 |
<td><code>'s'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
205 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
206 |
String format. This is the default type for strings and may be omitted. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
207 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
208 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
209 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
210 |
<td><code>'?'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
211 |
<td>Debug format. The string is quoted and special characters escaped.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
212 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
213 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
214 |
<td>none</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
215 |
<td>The same as <code>'s'</code>.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
216 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
217 |
</table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
218 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
219 |
The available character presentation types are: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
220 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
221 |
<table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
222 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
223 |
<th>Type</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
224 |
<th>Meaning</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
225 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
226 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
227 |
<td><code>'c'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
228 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
229 |
Character format. This is the default type for characters and may be |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
230 |
omitted. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
231 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
232 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
233 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
234 |
<td><code>'?'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
235 |
<td>Debug format. The character is quoted and special characters escaped.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
236 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
237 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
238 |
<td>none</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
239 |
<td>The same as <code>'c'</code>.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
240 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
241 |
</table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
242 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
243 |
The available integer presentation types are: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
244 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
245 |
<table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
246 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
247 |
<th>Type</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
248 |
<th>Meaning</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
249 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
250 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
251 |
<td><code>'b'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
252 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
253 |
Binary format. Outputs the number in base 2. Using the <code>'#'</code> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
254 |
option with this type adds the prefix <code>"0b"</code> to the output value. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
255 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
256 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
257 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
258 |
<td><code>'B'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
259 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
260 |
Binary format. Outputs the number in base 2. Using the <code>'#'</code> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
261 |
option with this type adds the prefix <code>"0B"</code> to the output value. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
262 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
263 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
264 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
265 |
<td><code>'c'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
266 |
<td>Character format. Outputs the number as a character.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
267 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
268 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
269 |
<td><code>'d'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
270 |
<td>Decimal integer. Outputs the number in base 10.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
271 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
272 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
273 |
<td><code>'o'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
274 |
<td>Octal format. Outputs the number in base 8.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
275 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
276 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
277 |
<td><code>'x'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
278 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
279 |
Hex format. Outputs the number in base 16, using lower-case letters for the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
280 |
digits above 9. Using the <code>'#'</code> option with this type adds the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
281 |
prefix <code>"0x"</code> to the output value. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
282 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
283 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
284 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
285 |
<td><code>'X'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
286 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
287 |
Hex format. Outputs the number in base 16, using upper-case letters for the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
288 |
digits above 9. Using the <code>'#'</code> option with this type adds the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
289 |
prefix <code>"0X"</code> to the output value. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
290 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
291 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
292 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
293 |
<td>none</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
294 |
<td>The same as <code>'d'</code>.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
295 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
296 |
</table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
297 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
298 |
Integer presentation types can also be used with character and Boolean values |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
299 |
with the only exception that `'c'` cannot be used with `bool`. Boolean values |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
300 |
are formatted using textual representation, either `true` or `false`, if the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
301 |
presentation type is not specified. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
302 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
303 |
The available presentation types for floating-point values are: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
304 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
305 |
<table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
306 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
307 |
<th>Type</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
308 |
<th>Meaning</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
309 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
310 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
311 |
<td><code>'a'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
312 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
313 |
Hexadecimal floating point format. Prints the number in base 16 with |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
314 |
prefix <code>"0x"</code> and lower-case letters for digits above 9. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
315 |
Uses <code>'p'</code> to indicate the exponent. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
316 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
317 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
318 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
319 |
<td><code>'A'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
320 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
321 |
Same as <code>'a'</code> except it uses upper-case letters for the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
322 |
prefix, digits above 9 and to indicate the exponent. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
323 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
324 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
325 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
326 |
<td><code>'e'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
327 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
328 |
Exponent notation. Prints the number in scientific notation using |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
329 |
the letter 'e' to indicate the exponent. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
330 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
331 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
332 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
333 |
<td><code>'E'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
334 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
335 |
Exponent notation. Same as <code>'e'</code> except it uses an |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
336 |
upper-case <code>'E'</code> as the separator character. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
337 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
338 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
339 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
340 |
<td><code>'f'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
341 |
<td>Fixed point. Displays the number as a fixed-point number.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
342 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
343 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
344 |
<td><code>'F'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
345 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
346 |
Fixed point. Same as <code>'f'</code>, but converts <code>nan</code> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
347 |
to <code>NAN</code> and <code>inf</code> to <code>INF</code>. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
348 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
349 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
350 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
351 |
<td><code>'g'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
352 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
353 |
<p>General format. For a given precision <code>p >= 1</code>, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
354 |
this rounds the number to <code>p</code> significant digits and then |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
355 |
formats the result in either fixed-point format or in scientific |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
356 |
notation, depending on its magnitude.</p> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
357 |
<p>A precision of <code>0</code> is treated as equivalent to a precision |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
358 |
of <code>1</code>.</p> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
359 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
360 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
361 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
362 |
<td><code>'G'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
363 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
364 |
General format. Same as <code>'g'</code> except switches to |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
365 |
<code>'E'</code> if the number gets too large. The representations of |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
366 |
infinity and NaN are uppercased, too. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
367 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
368 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
369 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
370 |
<td>none</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
371 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
372 |
Similar to <code>'g'</code>, except that the default precision is as |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
373 |
high as needed to represent the particular value. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
374 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
375 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
376 |
</table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
377 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
378 |
The available presentation types for pointers are: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
379 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
380 |
<table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
381 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
382 |
<th>Type</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
383 |
<th>Meaning</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
384 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
385 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
386 |
<td><code>'p'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
387 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
388 |
Pointer format. This is the default type for pointers and may be omitted. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
389 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
390 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
391 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
392 |
<td>none</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
393 |
<td>The same as <code>'p'</code>.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
394 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
395 |
</table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
396 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
397 |
## Chrono Format Specifications |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
398 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
399 |
Format specifications for chrono duration and time point types as well as |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
400 |
`std::tm` have the following syntax: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
401 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
402 |
<a id="chrono-format-spec"></a> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
403 |
<pre><code class="language-json" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
404 |
>chrono_format_spec ::= [[<a href="#format-spec">fill</a>]<a href="#format-spec" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
405 |
>align</a>][<a href="#format-spec">width</a>]["." <a href="#format-spec" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
406 |
>precision</a>][chrono_specs] |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
407 |
chrono_specs ::= conversion_spec | |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
408 |
chrono_specs (conversion_spec | literal_char) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
409 |
conversion_spec ::= "%" [padding_modifier] [locale_modifier] chrono_type |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
410 |
literal_char ::= <a character other than '{', '}' or '%'> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
411 |
padding_modifier ::= "-" | "_" | "0" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
412 |
locale_modifier ::= "E" | "O" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
413 |
chrono_type ::= "a" | "A" | "b" | "B" | "c" | "C" | "d" | "D" | "e" | |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
414 |
"F" | "g" | "G" | "h" | "H" | "I" | "j" | "m" | "M" | |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
415 |
"n" | "p" | "q" | "Q" | "r" | "R" | "S" | "t" | "T" | |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
416 |
"u" | "U" | "V" | "w" | "W" | "x" | "X" | "y" | "Y" | |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
417 |
"z" | "Z" | "%"</code> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
418 |
</pre> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
419 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
420 |
Literal chars are copied unchanged to the output. Precision is valid only |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
421 |
for `std::chrono::duration` types with a floating-point representation type. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
422 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
423 |
The available presentation types (*chrono_type*) are: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
424 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
425 |
<table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
426 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
427 |
<th>Type</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
428 |
<th>Meaning</th> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
429 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
430 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
431 |
<td><code>'a'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
432 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
433 |
The abbreviated weekday name, e.g. "Sat". If the value does not contain a |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
434 |
valid weekday, an exception of type <code>format_error</code> is thrown. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
435 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
436 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
437 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
438 |
<td><code>'A'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
439 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
440 |
The full weekday name, e.g. "Saturday". If the value does not contain a |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
441 |
valid weekday, an exception of type <code>format_error</code> is thrown. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
442 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
443 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
444 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
445 |
<td><code>'b'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
446 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
447 |
The abbreviated month name, e.g. "Nov". If the value does not contain a |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
448 |
valid month, an exception of type <code>format_error</code> is thrown. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
449 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
450 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
451 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
452 |
<td><code>'B'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
453 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
454 |
The full month name, e.g. "November". If the value does not contain a valid |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
455 |
month, an exception of type <code>format_error</code> is thrown. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
456 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
457 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
458 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
459 |
<td><code>'c'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
460 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
461 |
The date and time representation, e.g. "Sat Nov 12 22:04:00 1955". The |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
462 |
modified command <code>%Ec</code> produces the locale's alternate date and |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
463 |
time representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
464 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
465 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
466 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
467 |
<td><code>'C'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
468 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
469 |
The year divided by 100 using floored division, e.g. "19". If the result |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
470 |
is a single decimal digit, it is prefixed with 0. The modified command |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
471 |
<code>%EC</code> produces the locale's alternative representation of the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
472 |
century. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
473 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
474 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
475 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
476 |
<td><code>'d'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
477 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
478 |
The day of month as a decimal number. If the result is a single decimal |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
479 |
digit, it is prefixed with 0. The modified command <code>%Od</code> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
480 |
produces the locale's alternative representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
481 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
482 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
483 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
484 |
<td><code>'D'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
485 |
<td>Equivalent to <code>%m/%d/%y</code>, e.g. "11/12/55".</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
486 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
487 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
488 |
<td><code>'e'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
489 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
490 |
The day of month as a decimal number. If the result is a single decimal |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
491 |
digit, it is prefixed with a space. The modified command <code>%Oe</code> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
492 |
produces the locale's alternative representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
493 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
494 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
495 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
496 |
<td><code>'F'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
497 |
<td>Equivalent to <code>%Y-%m-%d</code>, e.g. "1955-11-12".</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
498 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
499 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
500 |
<td><code>'g'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
501 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
502 |
The last two decimal digits of the ISO week-based year. If the result is a |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
503 |
single digit it is prefixed by 0. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
504 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
505 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
506 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
507 |
<td><code>'G'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
508 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
509 |
The ISO week-based year as a decimal number. If the result is less than |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
510 |
four digits it is left-padded with 0 to four digits. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
511 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
512 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
513 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
514 |
<td><code>'h'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
515 |
<td>Equivalent to <code>%b</code>, e.g. "Nov".</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
516 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
517 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
518 |
<td><code>'H'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
519 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
520 |
The hour (24-hour clock) as a decimal number. If the result is a single |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
521 |
digit, it is prefixed with 0. The modified command <code>%OH</code> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
522 |
produces the locale's alternative representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
523 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
524 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
525 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
526 |
<td><code>'I'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
527 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
528 |
The hour (12-hour clock) as a decimal number. If the result is a single |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
529 |
digit, it is prefixed with 0. The modified command <code>%OI</code> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
530 |
produces the locale's alternative representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
531 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
532 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
533 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
534 |
<td><code>'j'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
535 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
536 |
If the type being formatted is a specialization of duration, the decimal |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
537 |
number of days without padding. Otherwise, the day of the year as a decimal |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
538 |
number. Jan 1 is 001. If the result is less than three digits, it is |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
539 |
left-padded with 0 to three digits. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
540 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
541 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
542 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
543 |
<td><code>'m'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
544 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
545 |
The month as a decimal number. Jan is 01. If the result is a single digit, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
546 |
it is prefixed with 0. The modified command <code>%Om</code> produces the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
547 |
locale's alternative representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
548 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
549 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
550 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
551 |
<td><code>'M'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
552 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
553 |
The minute as a decimal number. If the result is a single digit, it |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
554 |
is prefixed with 0. The modified command <code>%OM</code> produces the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
555 |
locale's alternative representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
556 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
557 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
558 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
559 |
<td><code>'n'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
560 |
<td>A new-line character.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
561 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
562 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
563 |
<td><code>'p'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
564 |
<td>The AM/PM designations associated with a 12-hour clock.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
565 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
566 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
567 |
<td><code>'q'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
568 |
<td>The duration's unit suffix.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
569 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
570 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
571 |
<td><code>'Q'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
572 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
573 |
The duration's numeric value (as if extracted via <code>.count()</code>). |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
574 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
575 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
576 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
577 |
<td><code>'r'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
578 |
<td>The 12-hour clock time, e.g. "10:04:00 PM".</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
579 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
580 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
581 |
<td><code>'R'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
582 |
<td>Equivalent to <code>%H:%M</code>, e.g. "22:04".</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
583 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
584 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
585 |
<td><code>'S'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
586 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
587 |
Seconds as a decimal number. If the number of seconds is less than 10, the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
588 |
result is prefixed with 0. If the precision of the input cannot be exactly |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
589 |
represented with seconds, then the format is a decimal floating-point number |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
590 |
with a fixed format and a precision matching that of the precision of the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
591 |
input (or to a microseconds precision if the conversion to floating-point |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
592 |
decimal seconds cannot be made within 18 fractional digits). The character |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
593 |
for the decimal point is localized according to the locale. The modified |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
594 |
command <code>%OS</code> produces the locale's alternative representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
595 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
596 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
597 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
598 |
<td><code>'t'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
599 |
<td>A horizontal-tab character.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
600 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
601 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
602 |
<td><code>'T'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
603 |
<td>Equivalent to <code>%H:%M:%S</code>.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
604 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
605 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
606 |
<td><code>'u'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
607 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
608 |
The ISO weekday as a decimal number (1-7), where Monday is 1. The modified |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
609 |
command <code>%Ou</code> produces the locale's alternative representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
610 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
611 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
612 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
613 |
<td><code>'U'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
614 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
615 |
The week number of the year as a decimal number. The first Sunday of the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
616 |
year is the first day of week 01. Days of the same year prior to that are |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
617 |
in week 00. If the result is a single digit, it is prefixed with 0. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
618 |
The modified command <code>%OU</code> produces the locale's alternative |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
619 |
representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
620 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
621 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
622 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
623 |
<td><code>'V'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
624 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
625 |
The ISO week-based week number as a decimal number. If the result is a |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
626 |
single digit, it is prefixed with 0. The modified command <code>%OV</code> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
627 |
produces the locale's alternative representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
628 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
629 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
630 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
631 |
<td><code>'w'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
632 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
633 |
The weekday as a decimal number (0-6), where Sunday is 0. The modified |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
634 |
command <code>%Ow</code> produces the locale's alternative representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
635 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
636 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
637 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
638 |
<td><code>'W'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
639 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
640 |
The week number of the year as a decimal number. The first Monday of the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
641 |
year is the first day of week 01. Days of the same year prior to that are |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
642 |
in week 00. If the result is a single digit, it is prefixed with 0. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
643 |
The modified command <code>%OW</code> produces the locale's alternative |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
644 |
representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
645 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
646 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
647 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
648 |
<td><code>'x'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
649 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
650 |
The date representation, e.g. "11/12/55". The modified command |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
651 |
<code>%Ex</code> produces the locale's alternate date representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
652 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
653 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
654 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
655 |
<td><code>'X'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
656 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
657 |
The time representation, e.g. "10:04:00". The modified command |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
658 |
<code>%EX</code> produces the locale's alternate time representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
659 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
660 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
661 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
662 |
<td><code>'y'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
663 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
664 |
The last two decimal digits of the year. If the result is a single digit |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
665 |
it is prefixed by 0. The modified command <code>%Oy</code> produces the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
666 |
locale's alternative representation. The modified command <code>%Ey</code> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
667 |
produces the locale's alternative representation of offset from |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
668 |
<code>%EC</code> (year only). |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
669 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
670 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
671 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
672 |
<td><code>'Y'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
673 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
674 |
The year as a decimal number. If the result is less than four digits it is |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
675 |
left-padded with 0 to four digits. The modified command <code>%EY</code> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
676 |
produces the locale's alternative full year representation. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
677 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
678 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
679 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
680 |
<td><code>'z'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
681 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
682 |
The offset from UTC in the ISO 8601:2004 format. For example -0430 refers |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
683 |
to 4 hours 30 minutes behind UTC. If the offset is zero, +0000 is used. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
684 |
The modified commands <code>%Ez</code> and <code>%Oz</code> insert a |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
685 |
<code>:</code> between the hours and minutes: -04:30. If the offset |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
686 |
information is not available, an exception of type |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
687 |
<code>format_error</code> is thrown. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
688 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
689 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
690 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
691 |
<td><code>'Z'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
692 |
<td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
693 |
The time zone abbreviation. If the time zone abbreviation is not available, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
694 |
an exception of type <code>format_error</code> is thrown. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
695 |
</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
696 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
697 |
<tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
698 |
<td><code>'%'</code></td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
699 |
<td>A % character.</td> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
700 |
</tr> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
701 |
</table> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
702 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
703 |
Specifiers that have a calendaric component such as `'d'` (the day of month) |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
704 |
are valid only for `std::tm` and time points but not durations. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
705 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
706 |
The available padding modifiers (*padding_modifier*) are: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
707 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
708 |
| Type | Meaning | |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
709 |
|-------|-----------------------------------------| |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
710 |
| `'-'` | Pad a numeric result with spaces. | |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
711 |
| `'_'` | Do not pad a numeric result string. | |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
712 |
| `'0'` | Pad a numeric result string with zeros. | |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
713 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
714 |
These modifiers are only supported for the `'H'`, `'I'`, `'M'`, `'S'`, `'U'`, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
715 |
`'V'` and `'W'` presentation types. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
716 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
717 |
## Range Format Specifications |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
718 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
719 |
Format specifications for range types have the following syntax: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
720 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
721 |
<pre><code class="language-json" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
722 |
>range_format_spec ::= ["n"][range_type][range_underlying_spec]</code> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
723 |
</pre> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
724 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
725 |
The `'n'` option formats the range without the opening and closing brackets. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
726 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
727 |
The available presentation types for `range_type` are: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
728 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
729 |
| Type | Meaning | |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
730 |
|--------|------------------------------------------------------------| |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
731 |
| none | Default format. | |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
732 |
| `'s'` | String format. The range is formatted as a string. | |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
733 |
| `'?s'` | Debug format. The range is formatted as an escaped string. | |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
734 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
735 |
If `range_type` is `'s'` or `'?s'`, the range element type must be a character |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
736 |
type. The `'n'` option and `range_underlying_spec` are mutually exclusive with |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
737 |
`'s'` and `'?s'`. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
738 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
739 |
The `range_underlying_spec` is parsed based on the formatter of the range's |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
740 |
element type. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
741 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
742 |
By default, a range of characters or strings is printed escaped and quoted. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
743 |
But if any `range_underlying_spec` is provided (even if it is empty), then the |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
744 |
characters or strings are printed according to the provided specification. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
745 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
746 |
Examples: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
747 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
748 |
```c++ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
749 |
fmt::print("{}", std::vector{10, 20, 30}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
750 |
// Output: [10, 20, 30] |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
751 |
fmt::print("{::#x}", std::vector{10, 20, 30}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
752 |
// Output: [0xa, 0x14, 0x1e] |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
753 |
fmt::print("{}", std::vector{'h', 'e', 'l', 'l', 'o'}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
754 |
// Output: ['h', 'e', 'l', 'l', 'o'] |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
755 |
fmt::print("{:n}", std::vector{'h', 'e', 'l', 'l', 'o'}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
756 |
// Output: 'h', 'e', 'l', 'l', 'o' |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
757 |
fmt::print("{:s}", std::vector{'h', 'e', 'l', 'l', 'o'}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
758 |
// Output: "hello" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
759 |
fmt::print("{:?s}", std::vector{'h', 'e', 'l', 'l', 'o', '\n'}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
760 |
// Output: "hello\n" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
761 |
fmt::print("{::}", std::vector{'h', 'e', 'l', 'l', 'o'}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
762 |
// Output: [h, e, l, l, o] |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
763 |
fmt::print("{::d}", std::vector{'h', 'e', 'l', 'l', 'o'}); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
764 |
// Output: [104, 101, 108, 108, 111] |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
765 |
``` |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
766 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
767 |
## Format Examples |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
768 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
769 |
This section contains examples of the format syntax and comparison with |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
770 |
the printf formatting. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
771 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
772 |
In most of the cases the syntax is similar to the printf formatting, |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
773 |
with the addition of the `{}` and with `:` used instead of `%`. For |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
774 |
example, `"%03.2f"` can be translated to `"{:03.2f}"`. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
775 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
776 |
The new format syntax also supports new and different options, shown in |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
777 |
the following examples. |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
778 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
779 |
Accessing arguments by position: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
780 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
781 |
```c++ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
782 |
fmt::format("{0}, {1}, {2}", 'a', 'b', 'c'); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
783 |
// Result: "a, b, c" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
784 |
fmt::format("{}, {}, {}", 'a', 'b', 'c'); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
785 |
// Result: "a, b, c" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
786 |
fmt::format("{2}, {1}, {0}", 'a', 'b', 'c'); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
787 |
// Result: "c, b, a" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
788 |
fmt::format("{0}{1}{0}", "abra", "cad"); // arguments' indices can be repeated |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
789 |
// Result: "abracadabra" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
790 |
``` |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
791 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
792 |
Aligning the text and specifying a width: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
793 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
794 |
```c++ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
795 |
fmt::format("{:<30}", "left aligned"); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
796 |
// Result: "left aligned " |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
797 |
fmt::format("{:>30}", "right aligned"); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
798 |
// Result: " right aligned" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
799 |
fmt::format("{:^30}", "centered"); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
800 |
// Result: " centered " |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
801 |
fmt::format("{:*^30}", "centered"); // use '*' as a fill char |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
802 |
// Result: "***********centered***********" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
803 |
``` |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
804 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
805 |
Dynamic width: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
806 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
807 |
```c++ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
808 |
fmt::format("{:<{}}", "left aligned", 30); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
809 |
// Result: "left aligned " |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
810 |
``` |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
811 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
812 |
Dynamic precision: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
813 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
814 |
```c++ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
815 |
fmt::format("{:.{}f}", 3.14, 1); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
816 |
// Result: "3.1" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
817 |
``` |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
818 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
819 |
Replacing `%+f`, `%-f`, and `% f` and specifying a sign: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
820 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
821 |
```c++ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
822 |
fmt::format("{:+f}; {:+f}", 3.14, -3.14); // show it always |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
823 |
// Result: "+3.140000; -3.140000" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
824 |
fmt::format("{: f}; {: f}", 3.14, -3.14); // show a space for positive numbers |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
825 |
// Result: " 3.140000; -3.140000" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
826 |
fmt::format("{:-f}; {:-f}", 3.14, -3.14); // show only the minus -- same as '{:f}; {:f}' |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
827 |
// Result: "3.140000; -3.140000" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
828 |
``` |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
829 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
830 |
Replacing `%x` and `%o` and converting the value to different bases: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
831 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
832 |
```c++ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
833 |
fmt::format("int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
834 |
// Result: "int: 42; hex: 2a; oct: 52; bin: 101010" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
835 |
// with 0x or 0 or 0b as prefix: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
836 |
fmt::format("int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}", 42); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
837 |
// Result: "int: 42; hex: 0x2a; oct: 052; bin: 0b101010" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
838 |
``` |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
839 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
840 |
Padded hex byte with prefix and always prints both hex characters: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
841 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
842 |
```c++ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
843 |
fmt::format("{:#04x}", 0); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
844 |
// Result: "0x00" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
845 |
``` |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
846 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
847 |
Box drawing using Unicode fill: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
848 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
849 |
```c++ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
850 |
fmt::print( |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
851 |
"┌{0:─^{2}}┐\n" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
852 |
"│{1: ^{2}}│\n" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
853 |
"└{0:─^{2}}┘\n", "", "Hello, world!", 20); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
854 |
``` |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
855 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
856 |
prints: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
857 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
858 |
``` |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
859 |
┌────────────────────┐ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
860 |
│ Hello, world! │ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
861 |
└────────────────────┘ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
862 |
``` |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
863 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
864 |
Using type-specific formatting: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
865 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
866 |
```c++ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
867 |
#include <fmt/chrono.h> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
868 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
869 |
auto t = tm(); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
870 |
t.tm_year = 2010 - 1900; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
871 |
t.tm_mon = 7; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
872 |
t.tm_mday = 4; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
873 |
t.tm_hour = 12; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
874 |
t.tm_min = 15; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
875 |
t.tm_sec = 58; |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
876 |
fmt::print("{:%Y-%m-%d %H:%M:%S}", t); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
877 |
// Prints: 2010-08-04 12:15:58 |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
878 |
``` |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
879 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
880 |
Using the comma as a thousands separator: |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
881 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
882 |
```c++ |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
883 |
#include <fmt/format.h> |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
884 |
|
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
885 |
auto s = fmt::format(std::locale("en_US.UTF-8"), "{:L}", 1234567890); |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
886 |
// s == "1,234,567,890" |
| 47fd5c32 |
Poul Sander |
2024-10-05 08:44 |
887 |
``` |
|
|
1970-01-01 00:00 |
888 |
|