{"id":5705,"date":"2019-06-13T15:01:49","date_gmt":"2019-06-13T15:01:49","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/c-core-guidelines-rules-about-strings\/"},"modified":"2023-06-27T07:59:49","modified_gmt":"2023-06-27T07:59:49","slug":"c-core-guidelines-rules-about-strings","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/c-core-guidelines-rules-about-strings\/","title":{"rendered":"C++ Core Guidelines: Rules for Strings"},"content":{"rendered":"<p>The C++ core guidelines use the term string as a sequence of characters. Consequently, the guidelines are about&nbsp; C-strings, C++-strings, the C++17 <span style=\"font-family: courier new, courier;\">std::string_view<\/span>&#8216;s, and <span style=\"font-family: courier new, courier;\">std::byte<\/span>&#8216;s.&nbsp;<\/p>\n<p><!--more--><\/p>\n<div id=\"simple-translate\">&nbsp;<\/div>\n<p>&nbsp;<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5700\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/thread-2995466_1280.jpg\" alt=\"thread 2995466 1280\" width=\"600\" height=\"400\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/thread-2995466_1280.jpg 1280w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/thread-2995466_1280-300x200.jpg 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/thread-2995466_1280-1024x682.jpg 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/thread-2995466_1280-768x512.jpg 768w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>I will in this post only loosely refer to the guidelines and ignore the strings which are part of the <a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#S-gsl\">guidelines support library, <\/a>such as <span style=\"font-family: courier new, courier;\">gsl::string_span, zstring<\/span>, and <span style=\"font-family: courier new, courier;\">czstring<\/span>. For short, I call in this post a<span style=\"font-family: courier new, courier;\"> std::string<\/span>, a C++-string, and a<span style=\"font-family: courier new, courier;\"> const char*<\/span> a C-string.<\/p>\n<p>Let me start with the first rule:<\/p>\n<h2><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Rstr-string\">SL.str.1: Use <code class=\"highlighter-rouge no-highlight\">std::string<\/code> to own character sequences<\/a><\/h2>\n<p>Maybe, you know another string that owns its character&#8217;s sequence: a C-string. Don&#8217;t use a C-string! Why? Because you have to take care of the memory management, the string termination character, and the string length.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ stringC.c<\/span>\r\n\r\n<span style=\"color: #009999;\">#include &lt;stdio.h&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;string.h&gt;<\/span>\r\n \r\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">main<\/span>( <span style=\"color: #007788; font-weight: bold;\">void<\/span> ){\r\n \r\n  <span style=\"color: #007788; font-weight: bold;\">char<\/span> text[<span style=\"color: #ff6600;\">10<\/span>];\r\n \r\n  strcpy(text, <span style=\"color: #cc3300;\">\"The Text is too long for text.\"<\/span>);   <span style=\"color: #0099ff; font-style: italic;\">\/\/ (1) text is too big<\/span>\r\n  printf(<span style=\"color: #cc3300;\">\"strlen(text): %u<\/span><span style=\"color: #cc3300; font-weight: bold;\">\\n<\/span><span style=\"color: #cc3300;\">\"<\/span>, strlen(text));       <span style=\"color: #0099ff; font-style: italic;\">\/\/ (2) text has no termination character '\\0'<\/span>\r\n  printf(<span style=\"color: #cc3300;\">\"%s<\/span><span style=\"color: #cc3300; font-weight: bold;\">\\n<\/span><span style=\"color: #cc3300;\">\"<\/span>, text);\r\n \r\n  text[<span style=\"color: #006699; font-weight: bold;\">sizeof<\/span>(text)<span style=\"color: #555555;\">-<\/span><span style=\"color: #ff6600;\">1<\/span>] <span style=\"color: #555555;\">=<\/span> <span style=\"color: #cc3300;\">'\\0'<\/span>;\r\n  printf(<span style=\"color: #cc3300;\">\"strlen(text): %u<\/span><span style=\"color: #cc3300; font-weight: bold;\">\\n<\/span><span style=\"color: #cc3300;\">\"<\/span>, strlen(text));\r\n \r\n  <span style=\"color: #006699; font-weight: bold;\">return<\/span> <span style=\"color: #ff6600;\">0<\/span>;\r\n}\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>The simple program <span style=\"font-family: courier new, courier;\">stringC.c<\/span> has inline (1) and line (2) undefined behavior. Compiling it with a rusty GCC 4.8 seems to work fine.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5701\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringC.png\" alt=\"stringC\" width=\"500\" height=\"145\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringC.png 1310w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringC-300x87.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringC-1024x298.png 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringC-768x223.png 768w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/>The C++ variant does not have the same issues.<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ stringCpp.cpp<\/span>\r\n\r\n<span style=\"color: #009999;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;string&gt;<\/span>\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">main<\/span>(){\r\n \r\n  std<span style=\"color: #555555;\">::<\/span>string text{<span style=\"color: #cc3300;\">\"The Text is not too long.\"<\/span>};  \r\n \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"text.size(): \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> text.size() <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> text <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n \r\n  text <span style=\"color: #555555;\">+=<\/span><span style=\"color: #cc3300;\">\" And can still grow!\"<\/span>;\r\n \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"text.size(): \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> text.size() <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> text <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n \r\n}\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>The output of the program should not surprise you.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5702\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringCpp.png\" alt=\"stringCpp\" width=\"500\" height=\"186\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringCpp.png 1022w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringCpp-300x112.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringCpp-768x286.png 768w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n<p>In the case of a C++ string, I cannot make an error because the C++ runtime takes care of the memory management and the termination character. Additionally, if you access the elements of the C++ string with the at-operator instead of the index operator, bounds errors are not possible. You can read the details of the at-operator in my previous post: <a href=\"https:\/\/www.modernescpp.com\/index.php\/c-core-guidelines-avoid-bound-errors\">C++ Core Guidelines: Avoid Bounds Errors<\/a>.<\/p>\n<p>You know, what was strange in C++, including C++11? There was no way to create a C++ string without a C-string. This is strange because we want to get rid of the C-string. This inconsistency is gone with C++14.<\/p>\n<\/p>\n<h2><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Rstr-s\">SL.str.12: Use the <code class=\"highlighter-rouge no-highlight\">s<\/code> suffix for string literals meant to be standard-library <code class=\"highlighter-rouge no-highlight\">string<\/code>s<\/a>&nbsp;<\/h2>\n<p>With C++14, we got C++-string literals. It&#8217;s a C-string literal with the suffix s: &#8220;<span style=\"font-family: courier new, courier;\">cStringLiteral&#8221;s<\/span>.<\/p>\n<p>Let me show you an example that makes my point: C-string literals and C++-string literals a different.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ stringLiteral.cpp<\/span>\r\n\r\n<span style=\"color: #009999;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;string&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;utility&gt;<\/span>\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">main<\/span>(){\r\n    \r\n    <span style=\"color: #006699; font-weight: bold;\">using<\/span> <span style=\"color: #006699; font-weight: bold;\">namespace<\/span> std<span style=\"color: #555555;\">::<\/span>string_literals;                         <span style=\"color: #0099ff; font-style: italic;\">\/\/ (1)<\/span>\r\n\r\n    std<span style=\"color: #555555;\">::<\/span>string hello <span style=\"color: #555555;\">=<\/span> <span style=\"color: #cc3300;\">\"hello\"<\/span>;                                  <span style=\"color: #0099ff; font-style: italic;\">\/\/ (2)<\/span>\r\n    \r\n    <span style=\"color: #006699; font-weight: bold;\">auto<\/span> firstPair <span style=\"color: #555555;\">=<\/span> std<span style=\"color: #555555;\">::<\/span>make_pair(hello, <span style=\"color: #ff6600;\">5<\/span>);\r\n    <span style=\"color: #006699; font-weight: bold;\">auto<\/span> secondPair <span style=\"color: #555555;\">=<\/span> std<span style=\"color: #555555;\">::<\/span>make_pair(<span style=\"color: #cc3300;\">\"hello\"<\/span>, <span style=\"color: #ff6600;\">15<\/span>);                <span style=\"color: #0099ff; font-style: italic;\">\/\/ (3)<\/span>\r\n    <span style=\"color: #0099ff; font-style: italic;\">\/\/ auto secondPair = std::make_pair(\"hello\"s, 15);            \/\/ (4)<\/span>\r\n    \r\n    <span style=\"color: #006699; font-weight: bold;\">if<\/span> (firstPair <span style=\"color: #555555;\">&lt;<\/span> secondPair) std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"true\"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl; <span style=\"color: #0099ff; font-style: italic;\">\/\/ (5)<\/span>\r\n    \r\n}\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>It&#8217;s a pity; I must include the namespace <span style=\"font-family: courier new, courier;\">std::string_literals<\/span> in line (1) to use the C++-string-literals. Line (2) is the critical line in the example. I use the C-string-literal <span style=\"font-family: courier new, courier;\">&#8220;hello&#8221;<\/span> to create a C++ string. This is why the type of <span style=\"font-family: courier new, courier;\">firstPair<\/span> is (<span style=\"font-family: courier new, courier;\">std::string, int<\/span>), but the type of the <span style=\"font-family: courier new, courier;\">secondPair<\/span> is (<span style=\"font-family: courier new, courier;\">const char*, int<\/span>). Ultimately, the comparison in line (5) fails because you can not compare different types. Look carefully at the last line of the error message:&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5703\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringLiteralsError.PNG\" alt=\"stringLiteralsError\" width=\"600\" height=\"238\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringLiteralsError.PNG 3056w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringLiteralsError-300x119.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringLiteralsError-1024x406.png 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringLiteralsError-768x304.png 768w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringLiteralsError-1536x609.png 1536w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringLiteralsError-2048x812.png 2048w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>When I use the C++-string-literal in line (4 ) instead of the C-string-literal in line (3), the program behaves as expected:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5704\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringLiterals.PNG\" alt=\"stringLiterals\" width=\"450\" height=\"217\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringLiterals.PNG 2180w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringLiterals-300x144.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringLiterals-1024x493.png 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringLiterals-768x370.png 768w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringLiterals-1536x739.png 1536w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/06\/stringLiterals-2048x985.png 2048w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/p>\n<p>C++-string-literals was a C++14 feature. Let&#8217;s jump three years further. With C++17, we got <span style=\"font-family: courier new, courier;\">std::string_view<\/span> and <span style=\"font-family: courier new, courier;\">std::byte<\/span>. I already wrote, in particular, about <span style=\"font-family: courier new, courier;\">std::string_view<\/span>. Therefore, I will only recap the most important facts.<\/p>\n<h2><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Rstr-view\">SL.str.2: Use <code class=\"highlighter-rouge no-highlight\">std::string_view<\/code> or <code class=\"highlighter-rouge no-highlight\">gsl::string_span<\/code> to refer to character sequences<\/a><\/h2>\n<p>Okay, a <span style=\"font-family: courier new, courier;\">std::string<\/span> view only refers to the character sequence. To say it more explicitly: A <span style=\"font-family: courier new, courier;\">std::string_view<\/span> does not own the character sequence. It represents<span style=\"font-family: 'Courier New', Courier, monospace;\"> <\/span>a view of a sequence of characters. This sequence of characters can be a C++ string or a C-string. A <span style=\"font-family: Courier New, Courier, monospace;\">std::string_view<\/span> only needs two pieces of information: the pointer to the character sequence and their length. It supports the reading part of the interface<span style=\"font-family: 'courier new', courier;\"> <\/span>of the <span style=\"font-family: courier new, courier;\">std::string<\/span>. Additionally to a <span style=\"font-family: courier new, courier;\">std::string, std::string_view<\/span> has two modifying operations: <span style=\"font-family: Courier New, Courier, monospace;\">remove_prefix<\/span> and <span style=\"font-family: Courier New, Courier, monospace;\">remove_suffix<\/span>.<\/p>\n<p>Maybe you wonder: Why do we need a <span style=\"font-family: courier new, courier;\">std::string_view<\/span>? A <span style=\"font-family: courier new, courier;\">std::string_view<\/span> is relatively cheap to copy and needs no memory. My previous post <a href=\"https:\/\/www.modernescpp.com\/index.php\/c-17-avoid-copying-with-std-string-view\">C++17 &#8211; Avoid Copying with std::string_view <\/a>shows the impressive performance numbers of a<span style=\"font-family: courier new, courier;\"> std::string_view<\/span>.<\/p>\n<p>As I already mentioned it, we got with C++17 also a <span style=\"font-family: courier new, courier;\">std::byte<\/span>.<\/p>\n<h2><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Rstr-char*\">SL.str.4: Use <code class=\"highlighter-rouge no-highlight\">char*<\/code> to refer to a single character<\/a> and<a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Rstr-byte\"> SL.str.5: Use <code class=\"highlighter-rouge no-highlight\">std::byte<\/code> to refer to byte values that do not necessarily represent characters<\/a><\/h2>\n<p>If you don&#8217;t follow rule str.4 and use <span style=\"font-family: courier new, courier;\">const char*<\/span> as a C-string, you may end with critical issues.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007788; font-weight: bold;\">char<\/span> arr[] <span style=\"color: #555555;\">=<\/span> {<span style=\"color: #cc3300;\">'a'<\/span>, <span style=\"color: #cc3300;\">'b'<\/span>, <span style=\"color: #cc3300;\">'c'<\/span>};\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">void<\/span> <span style=\"color: #cc00ff;\">print<\/span>(<span style=\"color: #006699; font-weight: bold;\">const<\/span> <span style=\"color: #007788; font-weight: bold;\">char<\/span><span style=\"color: #555555;\">*<\/span> p)\r\n{\r\n    cout <span style=\"color: #555555;\">&lt;&lt;<\/span> p <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n}\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">void<\/span> <span style=\"color: #cc00ff;\">use<\/span>()\r\n{\r\n    print(arr);   <span style=\"color: #0099ff; font-style: italic;\">\/\/ run-time error; potentially very bad<\/span>\r\n}\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: courier new, courier;\">arr<\/span> decays to a pointer when used as an argument of the function <span style=\"font-family: courier new, courier;\">print<\/span>. The undefined behavior is that <span style=\"font-family: courier new, courier;\">arr<\/span> is not zero-terminated. You&#8217;re mistaken if you now think you can use std::byte as a character.<\/p>\n<p><span style=\"font-family: courier new,courier;\">std::byte<\/span> is a distinct type implementing the concept of a byte as specified in the C++ language definition. This means a byte is not an integer or a character and is not open to programmer errors. Its job is to access object storage. Consequently, its interface consists only of methods for bitwise logical operations.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0000ff;\">namespace<\/span> std { \r\n\r\n  <span style=\"color: #0000ff;\">  template<\/span> &lt;<span style=\"color: #0000ff;\">class<\/span> <span style=\"color: #2b91af;\">IntType<\/span>&gt; \r\n        constexpr byte <span style=\"color: #0000ff;\">operator<\/span>&lt;&lt;(byte b, IntType shift); \r\n  <span style=\"color: #0000ff;\">  template<\/span> &lt;<span style=\"color: #0000ff;\">class<\/span> <span style=\"color: #2b91af;\">IntType<\/span>&gt; \r\n        constexpr byte <span style=\"color: #0000ff;\">operator<\/span>&gt;&gt;(byte b, IntType shift); \r\n    constexpr byte <span style=\"color: #0000ff;\">operator<\/span>|(byte l, byte r); \r\n    constexpr byte <span style=\"color: #0000ff;\">operator<\/span>&amp;(byte l, byte r); \r\n    constexpr byte <span style=\"color: #0000ff;\">operator<\/span>~(byte b); \r\n    constexpr byte <span style=\"color: #0000ff;\">operator<\/span>^(byte l, byte r); \r\n\r\n} \r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>You can use the function<span style=\"font-family: courier new,courier;\"> std::to_integer(std::byte b)<\/span> to convert a <span style=\"font-family: courier new,courier;\">std::byte<\/span> to an integer type and the call <span style=\"font-family: courier new,courier;\">std::byte{integer}<\/span> to do it the other way around. <span style=\"font-family: courier new,courier;\">integer<\/span> has to be a non-negative value smaller than <span style=\"font-family: courier new,courier;\">std::numeric_limits&lt;unsigned_char&gt;::max().<\/span><\/p>\n<h2>What&#8217;s next?<\/h2>\n<p>I&#8217;m almost done with the rules for the standard library. Only a few rules to iostreams and the C-standard library are left. So you know what I will write about in my <a href=\"https:\/\/www.modernescpp.com\/index.php\/c-core-guidelines-iostream\">next post.<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The C++ core guidelines use the term string as a sequence of characters. Consequently, the guidelines are about&nbsp; C-strings, C++-strings, the C++17 std::string_view&#8216;s, and std::byte&#8216;s.&nbsp;<\/p>\n","protected":false},"author":21,"featured_media":5700,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[372],"tags":[],"class_list":["post-5705","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-modern-c"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5705","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=5705"}],"version-history":[{"count":1,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5705\/revisions"}],"predecessor-version":[{"id":6784,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5705\/revisions\/6784"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/5700"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=5705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=5705"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=5705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}