{"id":1004,"date":"2020-04-14T19:17:50","date_gmt":"2020-04-15T02:17:50","guid":{"rendered":"http:\/\/209.126.2.187\/?p=1004"},"modified":"2020-04-30T21:25:01","modified_gmt":"2020-05-01T04:25:01","slug":"built-in-c-string-functions","status":"publish","type":"post","link":"https:\/\/nanzhou.cc\/index.php\/2020\/04\/14\/built-in-c-string-functions\/","title":{"rendered":"Built-in C++ String Functions"},"content":{"rendered":"\n<p>This post contains some useful functions in the standard library which simplify your codes regarding string processing. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">std::rotate*<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">template&lt; class ForwardIt >\nvoid rotate( ForwardIt first, ForwardIt n_first, ForwardIt last );<\/code><\/pre>\n\n\n\n<p>Performs a left rotation on a range of elements. Specifically, std::rotate swaps the elements in the range [first, last) in such a way that the element n_first becomes the first element of the new range and n_first &#8211; 1 becomes the last element.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">std::substr<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">string substr (size_t pos = 0, size_t len = npos) const;<\/code><\/pre>\n\n\n\n<p>Note that:<br>If pos is equal to the string length, the function returns an empty string.<br>If pos is <strong>greater<\/strong> <strong>than<\/strong> the string length, it <strong>throws<\/strong> out_of_range.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">std::find<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">size_t find (const string&amp; str, size_t pos = 0) const noexcept;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">std::string_view<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">string text_ = \"Hello World\";\nstring_view text(text_);\ncout &lt;&lt; text.substr(0, 5) &lt;&lt; endl; \/\/ substr is O(1)\nunordered_set&lt;string_view> s;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This post contains some useful functions in the standard library which simplify your codes regarding string processing. std::rotate* Performs a left rotation on a range of elements. Specifically, std::rotate swaps the elements in the range [first, last) in such a way that the element n_first becomes the first element of the new range and n_first&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,54],"tags":[],"class_list":["post-1004","post","type-post","status-publish","format-standard","hentry","category-alg","category-string"],"_links":{"self":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts\/1004","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/comments?post=1004"}],"version-history":[{"count":8,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts\/1004\/revisions"}],"predecessor-version":[{"id":1097,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts\/1004\/revisions\/1097"}],"wp:attachment":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/media?parent=1004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/categories?post=1004"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/tags?post=1004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}