{"id":9004,"date":"2024-01-29T10:27:51","date_gmt":"2024-01-29T10:27:51","guid":{"rendered":"https:\/\/www.modernescpp.com\/?p=9004"},"modified":"2024-01-29T10:27:52","modified_gmt":"2024-01-29T10:27:52","slug":"the-formatting-library-in-c20-the-format-string","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/the-formatting-library-in-c20-the-format-string\/","title":{"rendered":"The Formatting Library in C++20: The Format String"},"content":{"rendered":"\n<p>I introduced &#8220;<a href=\"https:\/\/www.modernescpp.com\/index.php\/the-formatting-library-in-c20\/\" data-type=\"link\" data-id=\"https:\/\/www.modernescpp.com\/index.php\/the-formatting-library-in-c20\/\">The Formatting Library in C++20<\/a>&#8221; in my last post. Today, I will dive deeper into the format specification of the format string.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"955\" height=\"392\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/TimelineCpp20CoreLanguage.png\" alt=\"\" class=\"wp-image-8964\" style=\"width:799px;height:auto\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/TimelineCpp20CoreLanguage.png 955w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/TimelineCpp20CoreLanguage-300x123.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/TimelineCpp20CoreLanguage-768x315.png 768w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/TimelineCpp20CoreLanguage-705x289.png 705w\" sizes=\"auto, (max-width: 955px) 100vw, 955px\" \/><\/figure>\n\n\n\n<p>Let me start with a short recap of the format string.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Syntax: <strong><code>std::format(FormatString, Args)<\/code><\/strong><\/li>\n<\/ul>\n\n\n\n<p>The format string <strong><code>FormatString<\/code><\/strong> consists of<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ordinary characters (except { and })<\/li>\n\n\n\n<li>Escape sequences {{ and }} that are replaced by { and }<\/li>\n\n\n\n<li>Replacement fields<\/li>\n<\/ul>\n\n\n\n<p>A replacement field has the format { }.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Argument ID<\/h2>\n\n\n\n<p>You can use an argument id and a colon inside the replacement field followed by a format specification. Both components are optional. The argument id allows you to specify the index of the arguments in <strong><code>Args<\/code><\/strong>. The ids start with 0. When you don\u2019t provide the argument id, the fields are filled in the same order as the arguments are given. Either all replacement fields have to use an argument id or none.<\/p>\n\n\n\n<p>Thanks to the argument id, you can reorder or address particular arguments.<\/p>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #f0f3f3; overflow:auto;width:auto;gray;border-width:.1em .1em .1em .8em\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #0099FF; font-style: italic\">\/\/ formatArgumentID.cpp<\/span>\n\n<span style=\"color: #009999\">#include &lt;format&gt;<\/span>\n<span style=\"color: #009999\">#include &lt;iostream&gt;<\/span>\n<span style=\"color: #009999\">#include &lt;string&gt;<\/span>\n \n<span style=\"color: #007788; font-weight: bold\">int<\/span> <span style=\"color: #CC00FF\">main<\/span>() {\n    \n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{} {}: {}!<\/span><span style=\"color: #CC3300; font-weight: bold\">\\n<\/span><span style=\"color: #CC3300\">&quot;<\/span>, <span style=\"color: #CC3300\">&quot;Hello&quot;<\/span>, <span style=\"color: #CC3300\">&quot;World&quot;<\/span>, <span style=\"color: #FF6600\">2020<\/span>);        <span style=\"color: #0099FF; font-style: italic\">\/\/ (1)<\/span>\n\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{1} {0}: {2}!<\/span><span style=\"color: #CC3300; font-weight: bold\">\\n<\/span><span style=\"color: #CC3300\">&quot;<\/span>, <span style=\"color: #CC3300\">&quot;World&quot;<\/span>, <span style=\"color: #CC3300\">&quot;Hello&quot;<\/span>, <span style=\"color: #FF6600\">2020<\/span>);     <span style=\"color: #0099FF; font-style: italic\">\/\/ (2)<\/span>\n\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{0} {0} {1}: {2}!<\/span><span style=\"color: #CC3300; font-weight: bold\">\\n<\/span><span style=\"color: #CC3300\">&quot;<\/span>, <span style=\"color: #CC3300\">&quot;Hello&quot;<\/span>, <span style=\"color: #CC3300\">&quot;World&quot;<\/span>, <span style=\"color: #FF6600\">2020<\/span>); <span style=\"color: #0099FF; font-style: italic\">\/\/ (3)<\/span>\n\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{0}: {2}!<\/span><span style=\"color: #CC3300; font-weight: bold\">\\n<\/span><span style=\"color: #CC3300\">&quot;<\/span>, <span style=\"color: #CC3300\">&quot;Hello&quot;<\/span>, <span style=\"color: #CC3300\">&quot;World&quot;<\/span>, <span style=\"color: #FF6600\">2020<\/span>);         <span style=\"color: #0099FF; font-style: italic\">\/\/ (4)<\/span>\n    \n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n   \n}\n<\/pre><\/div>\n\n\n\n<p>Line (1) displays the argument in the given order. On the contrary, line (2) reorders the first and second argument, line (3) shows the first argument twice, and line (4) ignores the second argument.<\/p>\n\n\n\n<p>For completeness, here is the output of the program:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"396\" height=\"229\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/formatArgumentID.png\" alt=\"\" class=\"wp-image-9009\" style=\"width:400px\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/formatArgumentID.png 396w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/formatArgumentID-300x173.png 300w\" sizes=\"auto, (max-width: 396px) 100vw, 396px\" \/><\/figure>\n\n\n\n<p>Applying the argument id with the format specification makes formatting text in C++20 very powerful.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Format Specification<\/h2>\n\n\n\n<p>I won&#8217;t present the format specification for basic types, string types, or chrono types. For basic types and <code>std::string<\/code>, read the full details here: <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/utility\/format\/formatter#Standard_format_specification\" data-type=\"link\" data-id=\"https:\/\/en.cppreference.com\/w\/cpp\/utility\/format\/formatter#Standard_format_specification\">standard format specification<\/a>. Accordingly, you can find the details of chrono types here: <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/chrono\/system_clock\/formatter#Format_specification\" data-type=\"link\" data-id=\"https:\/\/en.cppreference.com\/w\/cpp\/chrono\/system_clock\/formatter#Format_specification\">chrono format specification<\/a>.<\/p>\n\n\n\n<p>Instead, I present a pragmatic description of the format string for basic types, string types, and chrono types.<\/p>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #f0f3f3; overflow:auto;width:auto;gray;border-width:.1em .1em .1em .8em\"><pre style=\"margin: 0; line-height: 125%\">fill_align(opt) sign(opt) <span style=\"color: #AA0000; background-color: #FFAAAA\">#<\/span>(opt) <span style=\"color: #FF6600\">0<\/span>(opt) width(opt) precision(opt) L(opt) type(opt) \n<\/pre><\/div>\n\n\n\n<p>All parts are optional (opt). The following few sections present the features of this format specification.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Fill Character and Alignment<\/h3>\n\n\n\n<p>The fill character is optional (any character except<code> {<\/code> or <code>}<\/code>) and followed by an alignment specification. To use the fill character, you must specify the alignment.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Fill character: by default, space is used<\/li>\n\n\n\n<li>Alignment:\n<ul class=\"wp-block-list\">\n<li><code>&lt;<\/code>: left (default for non-numbers)<\/li>\n\n\n\n<li>&gt;: right (default for numbers)<\/li>\n\n\n\n<li>^: center<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #f0f3f3; overflow:auto;width:auto;gray;border-width:.1em .1em .1em .8em\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #0099FF; font-style: italic\">\/\/ formatFillAlign.cpp<\/span>\n\n<span style=\"color: #009999\">#include &lt;format&gt;<\/span>\n<span style=\"color: #009999\">#include &lt;iostream&gt;<\/span>\n \n<span style=\"color: #007788; font-weight: bold\">int<\/span> <span style=\"color: #CC00FF\">main<\/span>() {\n\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n    \n    <span style=\"color: #007788; font-weight: bold\">int<\/span> num <span style=\"color: #555555\">=<\/span> <span style=\"color: #FF6600\">2020<\/span>;\n\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{:6}&quot;<\/span>, num) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>; \n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{:6}&quot;<\/span>, <span style=\"color: #CC3300\">&#39;x&#39;<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;   \n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{:*&lt;6}&quot;<\/span>, <span style=\"color: #CC3300\">&#39;x&#39;<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{:*&gt;6}&quot;<\/span>, <span style=\"color: #CC3300\">&#39;x&#39;<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{:*^6}&quot;<\/span>, <span style=\"color: #CC3300\">&#39;x&#39;<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{:6d}&quot;<\/span>, num) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{:6}&quot;<\/span>, <span style=\"color: #336666\">true<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n   \n}\n<\/pre><\/div>\n\n\n\n<p>The default alignment depends on the used types. In contrast to the iostream operator, boolean values are displayed by default as <code>true <\/code>or <code>false<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"392\" height=\"276\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/formatFillAlign.png\" alt=\"\" class=\"wp-image-9013\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/formatFillAlign.png 392w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/formatFillAlign-300x211.png 300w\" sizes=\"auto, (max-width: 392px) 100vw, 392px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Sign, <code>#<\/code> and <code>0<\/code><\/h3>\n\n\n\n<p>The sign,<code> #<\/code>, and<code> 0<\/code> character is only valid when an integer or floating-point type is used.<\/p>\n\n\n\n<p>The sign can have the following values:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>+<\/code>: sign is used for zero and positive numbers<\/li>\n\n\n\n<li>-: sign is only used for negative numbers (default)<\/li>\n\n\n\n<li>space: leading space is used for non-negative numbers and a minus sign for negative numbers<\/li>\n<\/ul>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #f0f3f3; overflow:auto;width:auto;gray;border-width:.1em .1em .1em .8em\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #0099FF; font-style: italic\">\/\/ formatSign.cpp<\/span>\n\n<span style=\"color: #009999\">#include &lt;format&gt;<\/span>\n<span style=\"color: #009999\">#include &lt;iostream&gt;<\/span>\n \n<span style=\"color: #007788; font-weight: bold\">int<\/span> <span style=\"color: #CC00FF\">main<\/span>() {\n\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{0:},{0:+},{0:-},{0: }&quot;<\/span>, <span style=\"color: #FF6600\">0<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{0:},{0:+},{0:-},{0: }&quot;<\/span>, <span style=\"color: #555555\">-<\/span><span style=\"color: #FF6600\">0<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{0:},{0:+},{0:-},{0: }&quot;<\/span>, <span style=\"color: #FF6600\">1<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{0:},{0:+},{0:-},{0: }&quot;<\/span>, <span style=\"color: #555555\">-<\/span><span style=\"color: #FF6600\">1<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n   \n}\n<\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"354\" height=\"230\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/formatSign.png\" alt=\"\" class=\"wp-image-9017\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/formatSign.png 354w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/formatSign-300x195.png 300w\" sizes=\"auto, (max-width: 354px) 100vw, 354px\" \/><\/figure>\n\n\n\n<p>The<code> #<\/code> causes the alternative form:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>For integer types, the prefix<code> 0b<\/code>, <code>0<\/code>, or <code>0x <\/code>is used for binary, octal, or hexadecimal presented types<\/li>\n\n\n\n<li>For floating-point types, a decimal point is always used<\/li>\n\n\n\n<li><code>0<\/code>: pads with leading zeros<\/li>\n<\/ul>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #f0f3f3; overflow:auto;width:auto;gray;border-width:.1em .1em .1em .8em\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #0099FF; font-style: italic\">\/\/ formatAlternate.cpp<\/span>\n\n<span style=\"color: #009999\">#include &lt;format&gt;<\/span>\n<span style=\"color: #009999\">#include &lt;iostream&gt;<\/span>\n \n<span style=\"color: #007788; font-weight: bold\">int<\/span> <span style=\"color: #CC00FF\">main<\/span>() {\n\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{:#015}&quot;<\/span>, <span style=\"color: #FF6600\">0x78<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{:#015b}&quot;<\/span>, <span style=\"color: #FF6600\">0x78<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{:#015x}&quot;<\/span>, <span style=\"color: #FF6600\">0x78<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{:g}&quot;<\/span>, <span style=\"color: #FF6600\">120.0<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> std<span style=\"color: #555555\">::<\/span>format(<span style=\"color: #CC3300\">&quot;{:#g}&quot;<\/span>, <span style=\"color: #FF6600\">120.0<\/span>) <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n\n    std<span style=\"color: #555555\">::<\/span>cout <span style=\"color: #555555\">&lt;&lt;<\/span> <span style=\"color: #CC3300\">&#39;\\n&#39;<\/span>;\n   \n}\n<\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"385\" height=\"255\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/formatAlternate.png\" alt=\"\" class=\"wp-image-9020\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/formatAlternate.png 385w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/01\/formatAlternate-300x199.png 300w\" sizes=\"auto, (max-width: 385px) 100vw, 385px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p>The format specifier allows you to specify the width, precision, and the type of the value. I will write about it in my next post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I introduced &#8220;The Formatting Library in C++20&#8221; in my last post. Today, I will dive deeper into the format specification of the format string. Let me start with a short recap of the format string. The format string FormatString consists of A replacement field has the format { }. Argument ID You can use an [&hellip;]<\/p>\n","protected":false},"author":21,"featured_media":8964,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[375],"tags":[454],"class_list":["post-9004","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-20","tag-format"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/9004","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=9004"}],"version-history":[{"count":17,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/9004\/revisions"}],"predecessor-version":[{"id":9028,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/9004\/revisions\/9028"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/8964"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=9004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=9004"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=9004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}