{"id":110055,"date":"2026-09-25T19:25:24","date_gmt":"2026-09-25T11:25:24","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/110055.html"},"modified":"2026-09-25T19:25:24","modified_gmt":"2026-09-25T11:25:24","slug":"c%e8%af%ad%e8%a8%80%e5%8e%9f%e7%90%86%e4%b8%8e%e5%ae%9e%e8%b7%b5%e5%85%abstring%e7%b1%bb%e7%9a%84%e5%ba%95%e5%b1%82%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/110055.html","title":{"rendered":"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u516b):string\u7c7b\u7684\u5e95\u5c42\u5b9e\u73b0"},"content":{"rendered":"<p>\u672c\u7bc7\u76ee\u6807&#xff1a;<\/p>\n<p>\u638c\u63e1string\u7c7b\u7684\u90e8\u5206\u63a5\u53e3\u7684\u5b9e\u73b0<\/p>\n<\/p>\n<h2>\u4e00. string\u7c7b\u7684\u5e95\u5c42\u5b9e\u73b0<\/h2>\n<h3>1.\u6784\u9020\u51fd\u6570<\/h3>\n<p>\u9996\u5148\u6211\u4eec\u4e3a\u4e86\u4e0etsd\u5e93\u91cc\u9762\u7684string \u9694\u79bb\u4e00\u4e0b&#xff0c;\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u81ea\u5df1\u7684\u547d\u540d\u7a7a\u95f4&#xff0c;\u6211\u7684\u5c31\u662fkong\u4e86&#xff0c;C&#043;&#043; \u4e2d\u7684\u5b57\u7b26\u4e32\u672c\u8d28\u4e0a\u662f\u7531\u5b57\u7b26\u6570\u7ec4\u6784\u6210\u7684&#xff0c;\u800c C \u98ce\u683c\u5b57\u7b26\u4e32\u5e95\u5c42\u5c31\u662f&#xff1a;<\/p>\n<p>char*<\/p>\n<p>\u6240\u4ee5\u8fd9\u4e2a\u6a21\u62dfstring \u7c7b\u7684\u5927\u81f4\u6846\u67b6\u4e3a:<\/p>\n<p>\u5728string\u7c7b\u4e2d:<\/p>\n<p>#pragma once<br \/>\n#define _CRT_SECURE_NO_WARNINGS<br \/>\n#include &lt;iostream&gt;<br \/>\n#include &lt;assert.h&gt;<br \/>\nusing namespace std;<br \/>\nnamespace kong<br \/>\n{<br \/>\n    class string<br \/>\n    {<br \/>\n    public:<br \/>\n        string()<br \/>\n            :_str(nullptr),<br \/>\n             _size(0),<br \/>\n             _capacity(0)<br \/>\n        ~string()<br \/>\n        {}<br \/>\n    private:<br \/>\n        char*_str;<br \/>\n        size_t _size;<br \/>\n        size_t _capacity;<br \/>\n    };<br \/>\n}<\/p>\n<p>\u5176\u4e2d&#xff1a;<\/p>\n<ul>\n<li>_str \u6307\u5411\u52a8\u6001\u5f00\u8f9f\u7684\u5b57\u7b26\u7a7a\u95f4<\/li>\n<li>\u5b57\u7b26\u4e32\u5185\u5bb9\u5b58\u50a8\u5728 _str \u6307\u5411\u7684\u6570\u7ec4\u4e2d<\/li>\n<li>\n<p>_capacity\u8868\u793a\u5f53\u524d\u5f00\u8f9f\u7684\u5bb9\u91cf\u3002<\/p>\n<\/li>\n<li>\u5f53\u524d\u6709\u6548\u5b57\u7b26\u6570\u91cf\u3002<\/li>\n<\/ul>\n<p>\u7136\u540e\u6211\u4eec\u518d\u5b9e\u73b0\u4e00\u4e2ac_str\u7684\u63a5\u53e3&#xff0c;\u65b9\u4fbf\u540e\u9762\u770b\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u662f\u7b26\u5408\u6211\u4eec\u9884\u671f\u7ed3\u679c\u7684&#xff0c;\u8fd9\u4e2a\u8fd8\u662f\u6bd4\u8f83\u7b80\u5355\u7684&#xff0c;\u5982\u4ee3\u7801\u6240\u793a&#xff1a;<\/p>\n<p>const char* c_str()const { return _str; }<\/p>\n<p>\u90a3\u4e48\u5728string.cpp\u4e2d&#xff0c;<\/p>\n<p>#include &#034;string.h&#034;<\/p>\n<p>namespace kong<br \/>\n{<br \/>\n    void test_string1()<br \/>\n    {<br \/>\n        string s1;<br \/>\n        cout&lt;&lt;s1.c_str()&lt;&lt;endl;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u6ce8\u610f&#xff1a;\u8fd9\u4e2atest_string1\u4e5f\u5c31\u662f\u6d4b\u8bd5\u4ee3\u7801&#xff0c;\u6211\u4eec\u8fd8\u9700\u8981\u5728string.h\u91cc\u9762\u7684kong\u547d\u540d\u7a7a\u95f4\u91cc\u9762\u6709\u4e2a\u58f0\u660e&#xff0c;\u540e\u9762\u5c31\u4e0d\u518d\u63d0\u9192\u4e86\u3002<\/p>\n<p>\u6211\u4eec\u63a5\u4e0b\u6765\u5c31\u53ef\u4ee5\u76f4\u63a5\u5728test.cpp\u4e2d\u8fdb\u884c\u6d4b\u8bd5\u4e86&#xff0c;\u5982\u4ee3\u7801&#xff1a;<\/p>\n<p>#include &#034;string.h&#034;<\/p>\n<p>int main()<br \/>\n{<br \/>\n    test_string1();<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u6ce8\u610f:\u540e\u9762\u6211\u4eec\u4ec5\u9700\u5728\u8fd9\u91cc\u9762\u6dfb\u52a0\u4e00\u4e2a\u6d4b\u8bd5\u4ee3\u7801\u5373\u53ef&#xff0c;\u540e\u9762\u5c31\u4e0d\u5728\u6f14\u793a\u4e86&#xff0c;\u76f4\u63a5\u6d4b\u8bd5\u5373\u53ef\u3002<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"91\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260925112518-6ab65a1ee1e22.png\" width=\"1462\" \/><\/p>\n<p>\u53ef\u662f\u6211\u4eec\u53d1\u73b0\u8fd9\u4e2a\u5c45\u7136\u5931\u8d25\u4e86&#xff0c;\u8fd9\u662f\u4e3a\u5565\u554a&#xff1f;<\/p>\n<p>\u539f\u56e0&#xff1a;\u5176\u5b9e\u6211\u4eec\u5728\u7ed9 s1 \u521d\u59cb\u5316\u65f6&#xff0c;\u662f\u4f7f\u7528 nullptr \u521d\u59cb\u5316 _str \u7684\u3002\u4f46\u662f c_str() \u8fd4\u56de\u7684\u662f const char*&#xff0c;\u5b83\u9700\u8981\u8fd4\u56de\u4e00\u4e2a\u6709\u6548\u7684 C \u98ce\u683c\u5b57\u7b26\u4e32\u3002\u5982\u679c _str \u662f nullptr&#xff0c;\u90a3\u4e48\u8fd4\u56de\u7684\u5c31\u662f\u7a7a\u6307\u9488&#xff0c;\u540e\u7eed\u8bbf\u95ee\u65f6\u76f8\u5f53\u4e8e\u89e3\u5f15\u7528 nullptr&#xff0c;\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002\u56e0\u6b64&#xff0c;_str \u4e0d\u5e94\u8be5\u521d\u59cb\u5316\u4e3a nullptr&#xff0c;\u800c\u5e94\u8be5\u5f00\u8f9f\u4e00\u5757\u7a7a\u95f4\u5b58\u653e &#039;\\\\0&#039;&#xff0c;\u4fdd\u8bc1\u7a7a\u5b57\u7b26\u4e32\u4e5f\u7b26\u5408 C \u98ce\u683c\u5b57\u7b26\u4e32\u7684\u8981\u6c42\u3002<\/p>\n<p>\u6240\u4ee5\u6b63\u786e\u7684\u9ed8\u8ba4\u6784\u9020\u662f\u8fd9\u6837\u5b50\u7684&#xff1a;<\/p>\n<p>string():_str(new char[1]{&#039;\\\\0&#039;}),_size(0),_capacity(0)<br \/>\n{ }<\/p>\n<p>\u6709\u4e86\u8fd9\u4e2a\u4ee5\u540e&#xff0c;\u5176\u4ed6\u7684\u6784\u9020\u51fd\u6570\u4e5f\u662f\u6bd4\u8f83\u7b80\u5355\u7684&#xff0c;\u5982\u4ee3\u7801\u6240\u793a&#xff1a;<\/p>\n<p>\/\/\u6784\u9020\u51fd\u6570<br \/>\nstring(const char* str)<br \/>\n{<br \/>\nsize_t len &#061; strlen(str);<br \/>\n_size &#061; _capacity &#061; len;<br \/>\n_str &#061; new char[_capacity &#043; 1];<br \/>\nstrcpy(_str, str);<br \/>\n}<br \/>\n\/\/\u62f7\u8d1d\u6784\u9020\u51fd\u6570<br \/>\nstring(const string&amp; str)<br \/>\n{<br \/>\n_size &#061; str._size;<br \/>\n_capacity &#061; str._capacity;<br \/>\n_str &#061; new char[_capacity &#043; 1];<br \/>\nstrcpy(_str, str._str);<br \/>\n}<\/p>\n<h3>2.\u8d4b\u503c\u91cd\u8f7d\u4e0e\u6790\u6784\u51fd\u6570<\/h3>\n<p>\u5bf9\u4e8e\u8d4b\u503c\u91cd\u8f7d\u51fd\u6570\u6765\u8bf4&#xff0c;\u6211\u4eec\u9700\u8981\u8003\u8651\u88ab\u8d4b\u503c\u5bf9\u8c61\u539f\u6709\u7a7a\u95f4\u5927\u5c0f\u7684\u95ee\u9898\u3002\u5982\u679c\u8d4b\u503c\u5bf9\u8c61\u7684\u7a7a\u95f4\u6bd4\u5f53\u524d\u5bf9\u8c61\u5927\u6216\u8005\u5c0f&#xff0c;\u90fd\u53ef\u4ee5\u76f4\u63a5\u91ca\u653e\u539f\u6765\u7684\u7a7a\u95f4&#xff0c;\u7136\u540e\u6839\u636e\u65b0\u7684\u5b57\u7b26\u4e32\u957f\u5ea6\u91cd\u65b0\u5f00\u8f9f\u4e00\u5757\u5408\u9002\u5927\u5c0f\u7684\u7a7a\u95f4&#xff0c;\u518d\u8fdb\u884c\u6570\u636e\u62f7\u8d1d\u3002<\/p>\n<p>\u4f46\u662f\u8fd9\u91cc\u8fd8\u6709\u4e00\u4e2a\u9700\u8981\u6ce8\u610f\u7684\u95ee\u9898&#xff1a;\u5982\u679c\u51fa\u73b0\u81ea\u5df1\u7ed9\u81ea\u5df1\u8d4b\u503c\u7684\u60c5\u51b5&#xff0c;\u4f8b\u5982 s1 &#061; s1&#xff0c;\u5982\u679c\u4e0d\u63d0\u524d\u5224\u65ad&#xff0c;\u800c\u662f\u5148\u91ca\u653e\u539f\u6765\u7684\u7a7a\u95f4&#xff0c;\u518d\u4f7f\u7528 strcpy \u62f7\u8d1d\u6570\u636e&#xff0c;\u90a3\u4e48\u6b64\u65f6\u6e90\u6570\u636e\u5df2\u7ecf\u88ab\u91ca\u653e&#xff0c;\u540e\u7eed\u8bbf\u95ee\u4f1a\u5bfc\u81f4\u672a\u5b9a\u4e49\u884c\u4e3a\u3002\u56e0\u6b64&#xff0c;\u5728\u8d4b\u503c\u91cd\u8f7d\u51fd\u6570\u4e2d\u9700\u8981\u5148\u5224\u65ad\u662f\u5426\u4e3a\u81ea\u8eab\u8d4b\u503c&#xff0c;\u5982\u679c\u662f\u5219\u76f4\u63a5\u8fd4\u56de&#xff0c;\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u8d44\u6e90\u91ca\u653e\u3002<\/p>\n<p>\u4ee3\u7801\u5757&#xff1a;<\/p>\n<p>string&amp; operator&#061;(const string&amp; str)<br \/>\n{<br \/>\nif (this !&#061; &amp;str)<br \/>\n{<br \/>\ndelete[] _str;<br \/>\n_size &#061; str._size;<br \/>\n_capacity &#061; str._capacity;<br \/>\n_str &#061; new char[_capacity &#043; 1];<br \/>\nstrcpy(_str, str._str);<br \/>\n}<br \/>\nreturn *this;<br \/>\n}<\/p>\n<p>\u6790\u6784\u51fd\u6570&#xff1a;<\/p>\n<p>~string()<br \/>\n{<br \/>\n_size &#061; _capacity &#061; 0;<br \/>\ndelete[] _str;<br \/>\n_str &#061; nullptr;<br \/>\n}<\/p>\n<h3>3.\u5c0f\u63a5\u53e3\u5b9e\u73b0<\/h3>\n<p>char&amp; operator[] (size_t pos)<br \/>\n{<br \/>\nassert(pos &lt; _size);<br \/>\nreturn _str[pos];<br \/>\n}<br \/>\nconst char&amp; operator[] (size_t pos)const<br \/>\n{<br \/>\nassert(pos &lt; _size);<br \/>\nreturn _str[pos];<br \/>\n}<br \/>\nchar&amp; back() { return _str[_size &#8211; 1]; }<br \/>\nchar&amp; front() { return _str[0]; }<br \/>\nsize_t size()const { return _size; }<br \/>\nsize_t capacity() { return _capacity; }<br \/>\nvoid clear() { _size &#061; 0; }<br \/>\nbool empty() {return _capacity &#061;&#061; 0 ? true : false;}<\/p>\n<p>\u5176\u5b9e\u5bf9\u4e8e[]\u7684\u91cd\u8f7d&#xff0c;\u6211\u4eec\u9700\u8981\u6ce8\u610f\u5224\u65ad\u4e00\u4e0bpos\u7684\u4f4d\u7f6e\u662f\u5426\u5728_size\u7684\u8303\u56f4\u91cc\u9762\u3002<\/p>\n<h3>4.\u63d2\u5165\u63a5\u53e3<\/h3>\n<h4>4.1.push_back\u548cappend\u51fd\u6570<\/h4>\n<p>\u9996\u5148\u6211\u4eec\u9700\u8981\u6ce8\u610f\u7684\u662f&#xff0c;\u5728\u5411\u5b57\u7b26\u4e32\u5c3e\u90e8\u4e2d\u63d2\u5165\u5b57\u7b26\/\u5b57\u7b26\u4e32\u65f6&#xff0c;\u5982\u679c\u5f53\u524d\u7a7a\u95f4\u5df2\u7ecf\u6ee1\u4e86&#xff0c;\u90a3\u4e48\u5c31\u9700\u8981\u8fdb\u884c\u6269\u5bb9\u3002<\/p>\n<p>\u4f46\u662f\u5bf9\u4e8e C&#043;&#043; \u4e2d\u7684\u52a8\u6001\u6570\u7ec4\u6765\u8bf4&#xff0c;\u6211\u4eec\u65e0\u6cd5\u50cf C \u8bed\u8a00\u4e2d\u7684 realloc \u4e00\u6837\u76f4\u63a5\u5bf9\u539f\u7a7a\u95f4\u8fdb\u884c\u6269\u5bb9\u3002\u56e0\u4e3a realloc \u53ef\u80fd\u4f1a\u76f4\u63a5\u5728\u539f\u7a7a\u95f4\u540e\u9762\u6269\u5c55&#xff0c;\u4e5f\u53ef\u80fd\u4f1a\u91cd\u65b0\u7533\u8bf7\u4e00\u5757\u65b0\u7684\u7a7a\u95f4\u5e76\u62f7\u8d1d\u6570\u636e&#xff0c;\u800c C&#043;&#043; \u4e2d\u4f7f\u7528 new[] \u5f00\u8f9f\u7684\u7a7a\u95f4\u4e0d\u80fd\u76f4\u63a5\u6269\u5c55\u3002<\/p>\n<p>\u56e0\u6b64\u6309\u7167\u4e4b\u524d\u7684\u601d\u8def&#xff0c;\u6211\u4eec\u4ecd\u7136\u9700\u8981&#xff1a;<\/p>\n<li>\u5f00\u8f9f\u4e00\u5757\u65b0\u7684\u7a7a\u95f4&#xff1b;<\/li>\n<li>\u5c06\u539f\u6765\u7684\u5b57\u7b26\u4e32\u5185\u5bb9\u62f7\u8d1d\u8fc7\u53bb&#xff1b;<\/li>\n<li>\u91ca\u653e\u65e7\u7a7a\u95f4&#xff1b;<\/li>\n<li>\u8ba9 _str \u6307\u5411\u65b0\u7684\u7a7a\u95f4\u3002<\/li>\n<p>\u4f46\u662f\u8fd9\u91cc\u53c8\u6709\u4e00\u4e2a\u95ee\u9898&#xff1a;<\/p>\n<p>\u65b0\u7684\u7a7a\u95f4\u5e94\u8be5\u5f00\u8f9f\u591a\u5927\u5462&#xff1f;<\/p>\n<p>\u5bf9\u4e8e push_back \u63d2\u5165\u4e00\u4e2a\u5b57\u7b26\u6765\u8bf4&#xff0c;\u5982\u679c\u6bcf\u63d2\u5165\u4e00\u4e2a\u5b57\u7b26\u5c31\u53ea\u589e\u52a0\u4e00\u4e2a\u7a7a\u95f4&#xff1a;<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>\u63d2\u5165&#039;a&#039;  -&gt; \u6269\u5bb9\u4e00\u6b21<br \/>\n\u63d2\u5165&#039;b&#039;  -&gt; \u6269\u5bb9\u4e00\u6b21<br \/>\n\u63d2\u5165&#039;c&#039;  -&gt; \u6269\u5bb9\u4e00\u6b21<br \/>\n&#8230;<\/p>\n<p>\u90a3\u4e48\u6bcf\u6b21\u63d2\u5165\u5b57\u7b26\u90fd\u9700\u8981\u91cd\u65b0\u7533\u8bf7\u7a7a\u95f4&#xff0c;\u800c\u7533\u8bf7\u7a7a\u95f4\u672c\u8eab\u662f\u4e00\u4e2a\u6bd4\u8f83\u8017\u65f6\u7684\u64cd\u4f5c&#xff0c;\u4f1a\u4e25\u91cd\u964d\u4f4e\u6548\u7387\u3002<\/p>\n<p>\u6240\u4ee5\u5b9e\u9645\u5de5\u7a0b\u4e2d\u4e0d\u4f1a\u6bcf\u6b21\u53ea\u589e\u52a0\u4e00\u4e2a\u5b57\u7b26\u7684\u7a7a\u95f4&#xff0c;\u800c\u662f\u91c7\u7528\u6269\u5bb9\u673a\u5236\u3002<\/p>\n<p>\u901a\u5e38\u60c5\u51b5\u4e0b&#xff1a;<\/p>\n<p>new_capacity &#061; old_capacity * 2;<\/p>\n<p>\u4e5f\u5c31\u662f\u5c06\u5bb9\u91cf\u6269\u5927\u4e3a\u539f\u6765\u7684\u4e24\u500d\u3002<\/p>\n<p>\u8fd9\u6837\u53ef\u4ee5\u51cf\u5c11\u9891\u7e41\u7533\u8bf7\u7a7a\u95f4\u7684\u6b21\u6570\u3002<\/p>\n<p>\u4f46\u662f\u5bf9\u4e8e append \u51fd\u6570\u6765\u8bf4&#xff0c;\u60c5\u51b5\u53c8\u6709\u6240\u4e0d\u540c\u3002<\/p>\n<p>push_back \u6bcf\u6b21\u53ea\u63d2\u5165\u4e00\u4e2a\u5b57\u7b26&#xff1a;<\/p>\n<p>s.push_back(&#039;a&#039;);<\/p>\n<p>\u6240\u4ee5\u91c7\u7528\u500d\u589e\u6269\u5bb9\u6bd4\u8f83\u5408\u9002\u3002<\/p>\n<p>\u4f46\u662f append \u662f\u4e00\u6b21\u63d2\u5165\u4e00\u6574\u4e2a\u5b57\u7b26\u4e32&#xff1a;<\/p>\n<p>s.append(&#034;hello&#034;);<\/p>\n<p>\u5982\u679c\u4ecd\u7136\u6309\u7167\u539f\u6765\u7684 capacity * 2 \u6269\u5bb9&#xff0c;\u53ef\u80fd\u4f1a\u51fa\u73b0\u7a7a\u95f4\u4e0d\u8db3\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>\u5f53\u524d&#xff1a;<\/p>\n<p>_size &#061; 10<br \/>\n_capacity &#061; 16<\/p>\n<p>\u73b0\u5728\u8ffd\u52a0&#xff1a;<\/p>\n<p>&#034;abcdefghijklmnopqrstuvwxyz&#034;<\/p>\n<p>\u957f\u5ea6&#xff1a;<\/p>\n<p>len &#061; 26<\/p>\n<p>\u90a3\u4e48\u65b0\u7684\u9700\u6c42&#xff1a;<\/p>\n<p>_size &#043; len &#061; 36<\/p>\n<p>\u4f46\u662f&#xff1a;<\/p>\n<p>_capacity * 2 &#061; 32<\/p>\n<p>\u4ecd\u7136\u65e0\u6cd5\u6ee1\u8db3\u9700\u6c42\u3002<\/p>\n<p>\u6240\u4ee5\u5bf9\u4e8e append&#xff0c;\u6211\u4eec\u5e94\u8be5\u6839\u636e\u5b9e\u9645\u9700\u8981\u7684\u7a7a\u95f4\u8fdb\u884c\u6269\u5bb9&#xff1a;<\/p>\n<p>new_capacity &#061; _size &#043; len;<\/p>\n<p>\u4e5f\u5c31\u662f&#xff1a;\u5f53\u524d\u5b57\u7b26\u4e32\u957f\u5ea6 &#043; \u65b0\u63d2\u5165\u5b57\u7b26\u4e32\u957f\u5ea6\u3002<\/p>\n<p>\u8fd9\u6837\u80fd\u591f\u4fdd\u8bc1\u4e00\u6b21\u6269\u5bb9\u540e\u4e00\u5b9a\u80fd\u5b58\u653e\u65b0\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u4e0d\u8fc7\u5b9e\u9645\u5b9e\u73b0\u65f6&#xff0c;\u8fd8\u9700\u8981\u6ce8\u610f&#xff1a;<\/p>\n<p>\u5982\u679c&#xff1a;<\/p>\n<p>_size &#043; len &gt; _capacity<\/p>\n<p>\u624d\u9700\u8981\u6269\u5bb9\u3002<\/p>\n<p>\u5982\u679c&#xff1a;<\/p>\n<p>_size &#043; len &lt;&#061; _capacity<\/p>\n<p>\u8bf4\u660e\u5f53\u524d\u7a7a\u95f4\u5df2\u7ecf\u8db3\u591f&#xff0c;\u76f4\u63a5\u8fdb\u884c\u62f7\u8d1d\u5373\u53ef&#xff0c;\u4e0d\u9700\u8981\u91cd\u65b0\u7533\u8bf7\u7a7a\u95f4\u3002<\/p>\n<p>\u6709\u4e86\u4e0a\u9762\u7684\u8ba4\u8bc6&#xff0c;\u6211\u4eec\u7684\u4ee3\u7801\u5c31\u6bd4\u8f83\u597d\u5199\u4e86&#xff0c;<\/p>\n<p>reverse&#xff1a;<\/p>\n<p>\u9996\u5148\u6211\u4eec\u9700\u8981\u5728string.h\u58f0\u660e\u4e00\u4e0b\u9700\u8981\u5b9e\u73b0\u7684\u51fd\u6570&#xff0c;\u5c06\u58f0\u660e\u4e0e\u5b9a\u4e49\u5206\u79bb&#xff0c;\u540e\u9762\u6211\u5c31\u76f4\u63a5\u5728string.cpp\u4e2d\u5199\u63a5\u53e3\u7684\u4ee3\u7801&#xff1a;<\/p>\n<p>void reserve(size_t n &#061; 0);<br \/>\nvoid push_back(char ch);<br \/>\nvoid append(const char* str);<\/p>\n<p>void string::reserve(size_t n)<br \/>\n{<br \/>\nif (n &gt; _capacity)<br \/>\n{<br \/>\n_capacity &#061; n;<br \/>\nchar* str &#061; new char[_capacity &#043; 1];<br \/>\nstrcpy(str, _str);<br \/>\ndelete[] _str;<br \/>\n_str &#061; str;<br \/>\n}<br \/>\n}<\/p>\n<p>push_back&#xff1a;<\/p>\n<p>void string::push_back(char ch)<br \/>\n{<br \/>\nif (_size &#061;&#061; _capacity)<br \/>\n{<br \/>\nreserve(_capacity &#061;&#061; 0 ? 4 : 2 * _capacity);<br \/>\n}<br \/>\n_str[_size&#043;&#043;] &#061; ch;<br \/>\n_str[_size] &#061; &#039;\\\\0&#039;;<br \/>\n}<\/p>\n<p>append&#xff1a;<\/p>\n<p>void string::append(const char* str)<br \/>\n{<br \/>\nsize_t len &#061; strlen(str);<br \/>\nif (_size &#043; len &gt; _capacity)<br \/>\n{<br \/>\nreserve(_size &#043; len);<br \/>\n}<\/p>\n<p>strcpy(_str &#043; _size, str);<br \/>\n_size &#043;&#061; len;<br \/>\n}<\/p>\n<h4>4.2.insert\u63a5\u53e3<\/h4>\n<p>insert \u51fd\u6570\u4e3b\u8981\u7528\u4e8e\u5728\u5b57\u7b26\u4e32\u6307\u5b9a\u4f4d\u7f6e\u63d2\u5165\u6570\u636e\u3002\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d&#xff0c;\u63d2\u5165\u64cd\u4f5c\u6bd4\u8f83\u5e38\u89c1\u7684\u6709\u4e24\u79cd\u60c5\u51b5&#xff1a;<\/p>\n<ul>\n<li>\u63d2\u5165\u5355\u4e2a\u5b57\u7b26&#xff1b;<\/li>\n<li>\u63d2\u5165\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002<\/li>\n<\/ul>\n<p>\u56e0\u6b64\u6211\u4eec\u4e3b\u8981\u5b9e\u73b0\u8fd9\u4e24\u4e2a\u63a5\u53e3\u3002<\/p>\n<p>\u9996\u5148\u6765\u770b\u63d2\u5165\u5b57\u7b26\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>str &#061; &#034;hello&#034;<\/p>\n<p>\u5728 pos &#061; 2 \u4f4d\u7f6e\u63d2\u5165 &#039;X&#039;<\/p>\n<p>\u539f\u5b57\u7b26\u4e32&#xff1a;<\/p>\n<p>h e l l o<br \/>\n0 1 2 3 4<\/p>\n<p>\u63d2\u5165\u540e&#xff1a;<\/p>\n<p>h e X l l o<br \/>\n0 1 2 3 4 5<\/p>\n<p>\u53ef\u4ee5\u53d1\u73b0&#xff1a;\u63d2\u5165\u4f4d\u7f6e pos \u540e\u9762\u7684\u6240\u6709\u5b57\u7b26\u90fd\u9700\u8981\u5411\u540e\u79fb\u52a8\u4e00\u4e2a\u4f4d\u7f6e\u3002<\/p>\n<p>\u4e5f\u5c31\u662f&#xff1a;<\/p>\n<p>pos\u53ca\u540e\u9762\u7684\u5b57\u7b26<br \/>\n        \u2193<br \/>\n\u6574\u4f53\u5411\u540e\u79fb\u52a81\u4f4d<\/p>\n<p>\u79fb\u52a8\u5b8c\u6210\u540e&#xff1a;<\/p>\n<p>_str[pos] &#061; ch;<\/p>\n<p>\u5373\u53ef\u5c06\u65b0\u7684\u5b57\u7b26\u653e\u5165\u6307\u5b9a\u4f4d\u7f6e\u3002<\/p>\n<p>\u8fc7\u7a0b\u56fe&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1448\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260925112519-6ab65a1f85408.png\" width=\"1086\" \/><\/p>\n<p>\u4ee3\u7801\u5757&#xff1a;<\/p>\n<p>void string::insert(size_t pos, char ch)<br \/>\n{<br \/>\nassert(pos &lt;&#061; _size);<br \/>\n\/\/ \u6269\u5bb9<br \/>\nif (_size &#061;&#061; _capacity)<br \/>\n{<br \/>\nreserve(_capacity &#061;&#061; 0 ? 4 : _capacity * 2);<br \/>\n}<\/p>\n<p>\/\/ \u632a\u52a8\u6570\u636e<br \/>\nsize_t end &#061; _size;<br \/>\nwhile (end &gt;&#061; pos)<br \/>\n{<br \/>\n_str[end &#043; 1] &#061; _str[end];<br \/>\n&#8211;end;<br \/>\n}<\/p>\n<p>_str[pos] &#061; ch;<br \/>\n_size&#043;&#043;;<br \/>\n}<\/p>\n<p>\u6d4b\u8bd5\u4ee3\u7801&#xff1a;<\/p>\n<p>void test_string2()<br \/>\n{<br \/>\n    string s1;<br \/>\n    s1.insert(0,&#039;1&#039;);<br \/>\n    cout&lt;&lt;s1.c_str()&lt;&lt;endl;<br \/>\n}<\/p>\n<p>\u4f46\u662f\u5f53\u6211\u4eec\u8fd0\u884c\u4ee3\u7801\u65f6&#xff0c;\u4f1a\u53d1\u73b0\u7a0b\u5e8f\u5e76\u6ca1\u6709\u6b63\u5e38\u7ed3\u675f&#xff0c;\u800c\u662f\u51fa\u73b0\u4e86\u6b7b\u5faa\u73af\u3002<\/p>\n<p>\u90a3\u4e48\u95ee\u9898\u51fa\u5728\u54ea\u91cc\u5462&#xff1f;<\/p>\n<p>\u539f\u56e0&#xff1a;<\/p>\n<p>\u6211\u4eec\u6765\u770b\u6570\u636e\u79fb\u52a8\u90e8\u5206&#xff1a;<\/p>\n<p>size_t end &#061; _size;<\/p>\n<p>while(end &gt;&#061; pos)<br \/>\n{<br \/>\n    _str[end &#043; 1] &#061; _str[end];<br \/>\n    &#8211;end;<br \/>\n}<\/p>\n<p>\u5047\u8bbe&#xff1a;<\/p>\n<p>s1 &#061; &#034;&#034;<\/p>\n<p>\u6b64\u65f6&#xff1a;<\/p>\n<p>_size &#061; 0<br \/>\npos &#061; 0<\/p>\n<p>\u8fdb\u5165\u5faa\u73af&#xff1a;<\/p>\n<p>\u7b2c\u4e00\u6b21&#xff1a;<\/p>\n<p>end &#061; 0<\/p>\n<p>\u6ee1\u8db3&#xff1a;<\/p>\n<p>end &gt;&#061; pos<\/p>\n<p>\u6267\u884c&#xff1a;<\/p>\n<p>_str[1] &#061; _str[0];<\/p>\n<p>\u7136\u540e&#xff1a;<\/p>\n<p>&#8211;end;<\/p>\n<p>\u6b64\u65f6&#xff1a;<\/p>\n<p>end &#061; -1;<\/p>\n<p>\u770b\u8d77\u6765\u5e94\u8be5\u9000\u51fa\u5faa\u73af\u3002<\/p>\n<p>\u4f46\u662f\u95ee\u9898\u6765\u4e86&#xff1a;<\/p>\n<p>\u6211\u4eec\u7684 end \u7c7b\u578b\u662f&#xff1a;size_t&#xff0c;\u800c size_t \u662f\u4e00\u79cd\u65e0\u7b26\u53f7\u7c7b\u578b\u3002<\/p>\n<p>\u6240\u4ee5&#xff1a;-1\u4e0d\u80fd\u88ab\u5b58\u50a8\u3002<\/p>\n<p>\u5f53\u6267\u884c&#xff1a;&#8211;end\u65f6&#xff0c;end\u4f1a\u53d1\u751f\u65e0\u7b26\u53f7\u6574\u6570\u4e0b\u6ea2\u3002<\/p>\n<p>\u7ed3\u679c\u4e0d\u662f&#xff1a;<\/p>\n<p>-1<\/p>\n<p>\u800c\u662f&#xff1a;<\/p>\n<p>18446744073709551615<\/p>\n<p>&#xff08;64\u4f4d\u73af\u5883\u4e0b&#xff09;<\/p>\n<p>\u4e8e\u662f&#xff1a;<\/p>\n<p>end &gt;&#061; pos<\/p>\n<p>\u4ecd\u7136\u6210\u7acb\u3002<\/p>\n<p>\u5faa\u73af\u7ee7\u7eed\u6267\u884c&#xff1a;<\/p>\n<p>_str[end &#043; 1] &#061; _str[end];<\/p>\n<p>\u6700\u7ec8\u5bfc\u81f4\u7a0b\u5e8f\u4e00\u76f4\u8fd0\u884c&#xff0c;\u4e5f\u5c31\u662f\u6211\u4eec\u770b\u5230\u7684\u201c\u5361\u4f4f\u201d\u3002<\/p>\n<p>\u65e2\u7136\u6211\u5df2\u7ecf\u77e5\u9053\u95ee\u9898\u51fa\u73b0\u5728 size_t \u7c7b\u578b\u7684\u4e0b\u6ea2\u4e0a&#xff0c;\u90a3\u4e48\u6211\u76f4\u63a5\u5c06 end \u7684\u7c7b\u578b\u4fee\u6539\u4e3a int \u4e0d\u5c31\u53ef\u4ee5\u4e86\u5417&#xff1f;<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>int end &#061; _size;<\/p>\n<p>\u4f46\u662f\u6211\u4eec\u5b9e\u9645\u4fee\u6539\u540e\u8fd0\u884c\u4ee3\u7801&#xff0c;\u4ecd\u7136\u53ef\u80fd\u53d1\u73b0\u7a0b\u5e8f\u4f9d\u65e7\u51fa\u73b0\u6b7b\u5faa\u73af\u3002<\/p>\n<p>\u539f\u56e0&#xff1a;<\/p>\n<p>\u9519\u8bef\u771f\u6b63\u51fa\u73b0\u5728 while \u7684\u5224\u65ad\u6761\u4ef6\u4e0a&#xff1a;<\/p>\n<p>while(end &gt;&#061; pos)<\/p>\n<p>\u867d\u7136\u6211\u4eec\u5c06&#xff1a;end\u4fee\u6539\u6210\u4e86&#xff1a;int<\/p>\n<p>\u4f46\u662f&#xff1a;pos\u7684\u7c7b\u578b\u4ecd\u7136\u662f&#xff1a;size_t&#xff0c;\u800c size_t \u662f\u65e0\u7b26\u53f7\u6574\u578b\u3002<\/p>\n<p>\u5728 C&#043;&#043; \u4e2d&#xff0c;\u5f53\u6709\u7b26\u53f7\u6574\u6570\u548c\u65e0\u7b26\u53f7\u6574\u6570\u8fdb\u884c\u6bd4\u8f83\u65f6&#xff0c;\u4f1a\u53d1\u751f\u6574\u578b\u63d0\u5347&#xff0c;\u4e3a\u4e86\u4fdd\u8bc1\u6bd4\u8f83\u7ed3\u679c\u4e00\u81f4&#xff0c;int \u7c7b\u578b\u7684 end \u4f1a\u88ab\u8f6c\u6362\u6210 size_t \u7c7b\u578b\u3002\u56e0\u6b64\u4e5f\u4f1a\u89e6\u53d1\u4e0e\u4e0a\u9762\u4e00\u6837\u7684\u95ee\u9898&#xff0c;\u6240\u4ee5\u5b8c\u6574\u7684\u4fee\u6539\u662f\u5982\u4e0b&#xff1a;<\/p>\n<p>void string::insert(size_t pos, char ch)<br \/>\n{<br \/>\nassert(pos &lt;&#061; _size);<br \/>\n\/\/ \u6269\u5bb9<br \/>\nif (_size &#061;&#061; _capacity)<br \/>\n{<br \/>\nreserve(_capacity &#061;&#061; 0 ? 4 : _capacity * 2);<br \/>\n}<\/p>\n<p>\/\/ \u632a\u52a8\u6570\u636e<br \/>\n    \/\/ version1:<br \/>\nint end &#061; _size;<br \/>\nwhile (end &gt;&#061; (int)pos)<br \/>\n{<br \/>\n_str[end &#043; 1] &#061; _str[end];<br \/>\n&#8211;end;<br \/>\n}<br \/>\n    \/\/ version2:<br \/>\n\/*size_t end &#061; _size &#043; 1;<br \/>\nwhile (end &gt; pos)<br \/>\n    {<br \/>\n_str[end] &#061; _str[end &#8211; 1];<br \/>\n&#8211;end;<br \/>\n}*\/<br \/>\n_str[pos] &#061; ch;<br \/>\n_size&#043;&#043;;<br \/>\n}<\/p>\n<p>\u5176\u4e2d\u7248\u672c2\u7684\u4ee3\u7801\u4e5f\u662f\u53ef\u4ee5\u901a\u8fc7\u7684\u3002<\/p>\n<p>\u6709\u4e86\u5355\u4e2a\u5b57\u7b26\u7684\u63d2\u5165&#xff0c;\u90a3\u4e48\u591a\u5b57\u7b26\u63d2\u5165\u7684\u6d41\u7a0b\u5982\u56fe&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1536\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260925112520-6ab65a20d7a67.png\" width=\"1024\" \/><\/p>\n<h4>4.3.\u91cd\u8f7d&#043;&#061;\u51fd\u6570<\/h4>\n<p>\u65e2\u7136\u6211\u4eec\u5df2\u7ecf\u77e5\u9053\u4e86\u6709\u5173\u63d2\u5165\u7684\u64cd\u4f5c&#xff0c;\u90a3\u4e48\u5173\u4e8e&#043;&#061;\u91cd\u8f7d\u7684\u5b9e\u73b0\u5c31\u6bd4\u8f83\u7b80\u5355\u4e86&#xff0c;\u5982\u4ee3\u7801\u6240\u793a&#xff1a;<\/p>\n<p>string&amp; string::operator&#043;&#061; (const string&amp; str)<br \/>\n{<br \/>\nconst_iterator it &#061; str.cbegin();<br \/>\nwhile (it !&#061; str.cend())<br \/>\n{<br \/>\n*this &#043;&#061; *it;<br \/>\nit&#043;&#043;;<br \/>\n}<\/p>\n<p>return *this;<br \/>\n}<\/p>\n<p>string&amp; string::operator&#043;&#061; (const char* s)<br \/>\n{<br \/>\nappend(s);<\/p>\n<p>return *this;<br \/>\n}<\/p>\n<p>string&amp; string::operator&#043;&#061; (char ch)<br \/>\n{<br \/>\npush_back(ch);<\/p>\n<p>return *this;<br \/>\n}<\/p>\n<h3>5.\u5220\u9664\u63a5\u53e3<\/h3>\n<p>\u5173\u4e8e\u5220\u9664\u5b57\u7b26\u7684\u64cd\u4f5c&#xff0c;\u6211\u4eec\u9700\u8981\u5173\u6ce8\u7684\u4e00\u4e2a\u70b9\u5c31\u662f&#xff0c;\u5f53pos &lt; _size\u65f6&#xff0c;\u5982\u679c\u4ece pos \u5f00\u59cb&#xff0c;\u5269\u4f59\u5b57\u7b26\u7684\u4e2a\u6570\u662f _size &#8211; pos&#xff0c;\u90a3\u4e48\u5f53 len &gt;&#061; _size &#8211; pos&#xff0c;\u6216\u8005 len &#061;&#061; string::npos \u65f6&#xff0c;\u5c31\u76f8\u5f53\u4e8e\u5220\u5230\u672b\u5c3e\u3002\u8fd9\u65f6\u628a _str[pos] \u6539\u6210 &#039;\\\\0&#039;&#xff0c;\u518d\u628a _size \u6539\u6210 pos&#xff0c;\u5b57\u7b26\u4e32\u5c31\u88ab\u622a\u65ad\u4e86\u3002\u53ea\u5199 &#039;\\\\0&#039; \u8fd8\u4e0d\u591f&#xff0c;\u957f\u5ea6\u4e5f\u8981\u540c\u6b65\u66f4\u65b0\u3002<\/p>\n<p>\u5982\u679c len &lt; _size &#8211; pos&#xff0c;\u8bf4\u660e\u88ab\u5220\u9664\u90e8\u5206\u540e\u9762\u8fd8\u6709\u5b57\u7b26\u9700\u8981\u4fdd\u7559\u3002\u6bd4\u5982&#xff1a;<\/p>\n<p>\u539f\u5b57\u7b26\u4e32&#xff1a;a b c d e f \\\\0<br \/>\n\u4e0b\u6807&#xff1a;    0 1 2 3 4 5  6<\/p>\n<p>\u6267\u884c erase(2, 2)&#xff0c;\u8981\u5220\u6389\u4e0b\u6807 2\u30013 \u7684 c\u3001d\u3002\u4e0b\u6807 4 \u7684 e \u662f\u5220\u9664\u8303\u56f4\u540e\u9762\u7b2c\u4e00\u4e2a\u8981\u4fdd\u7559\u7684\u5b57\u7b26&#xff0c;\u6240\u4ee5\u5148\u628a\u5b83\u653e\u5230\u4e0b\u6807 2&#xff0c;\u586b\u4e0a\u7b2c\u4e00\u4e2a\u7a7a\u4f4d\u3002\u7136\u540e\u628a f \u4ece\u4e0b\u6807 5 \u653e\u5230\u4e0b\u6807 3\u3002\u6700\u540e&#xff0c;\u8fd8\u5f97\u628a &#039;\\\\0&#039; \u4ece\u4e0b\u6807 6 \u653e\u5230\u4e0b\u6807 4&#xff1a;<\/p>\n<p>4 \u2192 2&#xff1a;\u642c e<br \/>\n5 \u2192 3&#xff1a;\u642c f<br \/>\n6 \u2192 4&#xff1a;\u642c \\\\0<\/p>\n<p>\u7ed3\u679c&#xff1a;a b e f \\\\0<\/p>\n<p>\u56e0\u6b64&#xff0c;\u632a\u52a8\u65f6\u6709\u4e24\u4e2a\u4f4d\u7f6e\u540c\u65f6\u5f80\u540e\u8d70&#xff1a;\u8bfb\u53d6\u4f4d\u7f6e\u4ece pos &#043; len \u5f00\u59cb&#xff0c;\u5199\u5165\u4f4d\u7f6e\u4ece pos \u5f00\u59cb\u3002\u4e00\u76f4\u642c\u5230\u539f\u6765 _size \u6240\u5728\u7684\u4f4d\u7f6e&#xff0c;\u628a &#039;\\\\0&#039; \u4e5f\u642c\u8fc7\u53bb\u3002\u642c\u5b8c\u518d\u6267\u884c _size -&#061; len\u3002\u56e0\u4e3a\u662f\u5f80\u5de6\u632a&#xff0c;\u6309\u4ece\u5de6\u5230\u53f3\u7684\u987a\u5e8f\u642c\u5c31\u53ef\u4ee5&#xff1a;\u6bcf\u6b21\u5199\u5165\u7684\u4f4d\u7f6e\u90fd\u5728\u5f53\u524d\u8bfb\u53d6\u4f4d\u7f6e\u7684\u524d\u9762&#xff0c;\u4e0d\u4f1a\u76d6\u6389\u540e\u9762\u5c1a\u672a\u8bfb\u53d6\u7684\u5b57\u7b26\u3002<\/p>\n<p>\u4f46\u662f\u6211\u4eec\u9700\u8981\u73b0\u5728\u7c7b\u91cc\u9762\u5b9a\u4e49\u4e00\u4e0b\u8fd9\u4e2anpos&#xff0c;\u4ec5\u9700static const size_t npos&#061;-1;\u5373\u53ef\u3002<\/p>\n<p>\u6d41\u7a0b\u56fe&#xff1a;<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260925112521-6ab65a21ee8fc.png\" \/><\/p>\n<p>\u4ee3\u7801\u5757&#xff1a;<\/p>\n<p>void string::erase(size_t pos, size_t len)<br \/>\n{<br \/>\nassert(pos &lt; _size);<br \/>\n\/\/ pos\u4ee5\u540e\u7684\u90fd\u8981\u5220\u9664<br \/>\nif (len &#061;&#061; string::npos || len &gt;&#061; _size &#8211; pos)<br \/>\n{<br \/>\n_str[pos] &#061; &#039;\\\\0&#039;;<br \/>\n_size &#061; pos;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nfor (size_t i &#061; pos &#043; len; i &lt;&#061; _size; i&#043;&#043;)<br \/>\n{<br \/>\n_str[pos&#043;&#043;] &#061; _str[i];<br \/>\n}<br \/>\n_size -&#061; len;<br \/>\n}<br \/>\n}<\/p>\n<h3>6.\u67e5\u627e\u63a5\u53e3<\/h3>\n<p>\u5173\u4e8e\u67e5\u627e\u7684\u63a5\u53e3&#xff0c;\u6211\u4eec\u4e3b\u8981\u5b9e\u73b0\u67e5\u627e\u4e00\u4e2a\u5b57\u7b26\u548c\u67e5\u627e\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u67e5\u627e\u4e00\u4e2a\u5b57\u7b26\u7684\u6bd4\u8f83\u597d\u5b9e\u73b0&#xff0c;\u904d\u5386\u5b57\u7b26\u4e00\u904d&#xff0c;\u770b\u770b\u6709\u6ca1\u6709\u5339\u914d\u7684\u5b57\u7b26&#xff0c;\u6709\u5c31\u8fd4\u56de\u4e0b\u6807&#xff0c;\u6ca1\u6709\u5c31\u8fd4\u56de<\/p>\n<p>npos&#xff0c;\u5982\u4ee3\u7801\u6240\u793a&#xff1a;<\/p>\n<p>size_t string::find(char ch, size_t pos)const<br \/>\n{<br \/>\nassert(pos &lt; _size);<br \/>\nfor (int i &#061; pos; i &lt; _size; i&#043;&#043;)<br \/>\n{<br \/>\nif (_str[i] &#061;&#061; ch)<br \/>\n{<br \/>\nreturn i;<br \/>\n}<br \/>\n}<\/p>\n<p>return npos;<br \/>\n}<\/p>\n<p>\u53ef\u662f\u5bf9\u4e8e\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u67e5\u627e&#xff0c;\u76ee\u524d\u6211\u4eec\u53ef\u4ee5\u66b4\u529b\u5339\u914d&#xff0c;\u4e00\u4e2a\u4e00\u4e2a\u5b57\u7b26\u7684\u6bd4\u5bf9&#xff0c;\u4f46\u662f\u6211\u4eec\u53ef\u4ee5\u7528\u4e00\u4e2a\u51fd\u6570\u89e3\u51b3&#xff0c;\u5373strstr\u51fd\u6570\u3002<\/p>\n<p>\u4f7f\u7528\u5982\u4e0b&#xff1a;<\/p>\n<p>strstr \u53ef\u4ee5\u76f4\u63a5\u7406\u89e3\u4e3a&#xff1a;\u62ff\u4e00\u4e2a\u5c0f\u5b57\u7b26\u4e32&#xff0c;\u53bb\u4e00\u4e2a\u5927\u5b57\u7b26\u4e32\u91cc\u627e&#xff0c;\u8c03\u7528\u65f6&#xff0c;\u7b2c\u4e00\u4e2a\u53c2\u6570\u653e\u5927\u5b57\u7b26\u4e32&#xff0c;\u7b2c\u4e8c\u4e2a\u53c2\u6570\u653e\u8981\u627e\u7684\u5c0f\u5b57\u7b26\u4e32\u3002\u6bd4\u5982\u5728 &#034;ababcabc&#034; \u91cc\u627e &#034;abc&#034;&#xff0c;\u5c31\u662f\u8ba9\u5b83\u4ece\u5de6\u5f80\u53f3\u68c0\u67e5&#xff0c;\u627e\u5230\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684 &#034;abc&#034;\u3002<\/p>\n<p>\u5b83\u8fd4\u56de\u7684\u4e0d\u662f\u4e0b\u6807 2&#xff0c;\u800c\u662f\u6307\u5411\u90a3\u4e2a a \u7684\u6307\u9488\u3002\u8fd9\u4e2a a \u662f\u5927\u5b57\u7b26\u4e32\u4e2d\u4e0b\u6807 2 \u7684\u5b57\u7b26&#xff0c;\u6240\u4ee5\u8fd4\u56de\u7684\u6307\u9488\u6307\u5411\u5927\u5b57\u7b26\u4e32\u5185\u90e8&#xff1b;\u4ece\u8fd9\u4e2a\u4f4d\u7f6e\u5f80\u540e\u770b&#xff0c;\u5185\u5bb9\u5c31\u662f &#034;abcabc&#034;\u3002\u5982\u679c\u4f60\u60f3\u77e5\u9053\u201c\u4ece\u7b2c\u51e0\u4e2a\u5b57\u7b26\u5f00\u59cb\u5339\u914d\u201d&#xff0c;\u624d\u7528\u8fd4\u56de\u7684\u6307\u9488\u51cf\u53bb\u5927\u5b57\u7b26\u4e32\u7684\u8d77\u59cb\u6307\u9488&#xff0c;\u5f97\u5230 2\u3002<\/p>\n<p>\u6ca1\u627e\u5230\u65f6&#xff0c;\u5b83\u8fd4\u56de\u7a7a\u6307\u9488\u3002\u8fd8\u6709\u4e00\u70b9&#xff1a;strstr \u627e\u7684\u662f\u4ee5 &#039;\\\\0&#039; \u7ed3\u5c3e\u7684\u5b57\u7b26\u5b57\u7b26\u4e32&#xff0c;\u6240\u4ee5\u653e\u5230\u4f60\u6b63\u5728\u5199\u7684 string \u7c7b\u91cc\u7406\u89e3&#xff0c;\u5c31\u662f\u62ff _str \u8fd9\u6837\u7684\u5b57\u7b26\u6570\u7ec4\u53bb\u67e5&#xff0c;\u800c\u4e0d\u662f\u8ba9\u5b83\u76f4\u63a5\u5904\u7406\u6574\u4e2a string \u5bf9\u8c61\u3002<\/p>\n<p>\u6240\u4ee5\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>size_t string::find(const char* s, size_t pos )const<br \/>\n{<br \/>\nassert(pos &lt; _size);<\/p>\n<p>char*str&#061; strstr(_str, s);<br \/>\nif (str &#061;&#061; nullptr)<br \/>\n{<br \/>\nreturn npos;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nreturn str &#8211; _str;<br \/>\n}<br \/>\n}<\/p>\n<h3>7.\u6bd4\u8f83\u5b57\u7b26\u4e32<\/h3>\n<p>\u81f3\u4e8e\u8fd9\u4e2a\u6bd4\u8f83\u51fd\u6570&#xff0c;\u6211\u4eec\u9700\u8981\u91cd\u8f7d&gt;&#xff0c;&lt;&#xff0c;&#061;&#061;&#xff0c;&gt;&#061;&#xff0c;!&#061;&#xff0c;&lt;&#061;\u5373\u53ef&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5148\u91cd\u8f7d&gt;\u548c&#061;&#061;\u5373\u53ef&#xff0c;\u5176\u4ed6\u7684\u51fd\u6570\u590d\u7528\u5373\u53ef&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>bool operator&gt;(const string&amp; s1, const string&amp; s2)<br \/>\n{<br \/>\nreturn strcmp(s1.c_str(), s2.c_str())&gt;0;<br \/>\n}<br \/>\nbool operator&gt;&#061;(const string&amp; s1, const string&amp; s2)<br \/>\n{<br \/>\nreturn s1 &gt; s2 || s1 &#061;&#061; s2;<br \/>\n}<br \/>\nbool operator&#061;&#061;(const string&amp; s1, const string&amp; s2)<br \/>\n{<br \/>\nreturn strcmp(s1.c_str(), s2.c_str()) &#061;&#061; 0;<br \/>\n}<br \/>\nbool operator&lt;(const string&amp; s1, const string&amp; s2)<br \/>\n{<br \/>\nreturn !(s1 &gt;&#061; s2);<br \/>\n}<br \/>\nbool operator&lt;&#061;(const string&amp; s1, const string&amp; s2)<br \/>\n{<br \/>\nreturn !(s1 &gt; s2);<br \/>\n}<br \/>\nbool operator!&#061;(const string&amp; s1, const string&amp; s2)<br \/>\n{<br \/>\nreturn !(s1 &#061;&#061; s2);<br \/>\n}<\/p>\n<h3>8.\u91cd\u8f7d&gt;&gt;\u548c&lt;&lt;\u51fd\u6570<\/h3>\n<p>\u8fd9\u4e2a&gt;&gt;\u7684\u91cd\u8f7d\u975e\u5e38\u7684\u7b80\u5355&#xff0c;\u6211\u4eec\u4ec5\u9700\u8f93\u51fa\u5b57\u7b26\u5373\u53ef&#xff0c;\u5982\u4ee3\u7801&#xff1a;<\/p>\n<p>ostream&amp; operator&lt;&lt;(ostream&amp; out, const string&amp; str)<br \/>\n{<br \/>\nfor (size_t i &#061; 0; i &lt; str.size(); i&#043;&#043;)<br \/>\n{<br \/>\nout &lt;&lt; str[i];<br \/>\n}<\/p>\n<p>return out;<br \/>\n}<\/p>\n<p>\u81f3\u4e8e\u6d41\u63d0\u53d6&#xff1a;<\/p>\n<p>\u9996\u5148\u8c03\u7528 str.clear()&#xff0c;\u6e05\u7a7a\u5b57\u7b26\u4e32\u539f\u6709\u7684\u5185\u5bb9&#xff0c;\u8ba9\u8fd9\u6b21\u8f93\u5165\u4ece\u7a7a\u5b57\u7b26\u4e32\u5f00\u59cb\u3002\u968f\u540e\u7528 in.get() \u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26\u3002\u53ea\u8981\u8bfb\u5230\u7684\u5b57\u7b26\u4e0d\u662f\u7a7a\u683c &#039; &#039;&#xff0c;\u4e5f\u4e0d\u662f\u6362\u884c\u7b26 &#039;\\\\n&#039;&#xff0c;\u5c31\u901a\u8fc7 str &#043;&#061; ch \u5c06\u5b83\u8ffd\u52a0\u5230\u5b57\u7b26\u4e32\u672b\u5c3e&#xff0c;\u518d\u8bfb\u53d6\u4e0b\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<p>\u4f8b\u5982\u8f93\u5165\u5185\u5bb9\u662f &#034;hello world\\\\n&#034;&#xff1a;\u7b2c\u4e00\u6b21\u8bfb\u53d6\u65f6&#xff0c;h\u3001e\u3001l\u3001l\u3001o \u4f1a\u4f9d\u6b21\u52a0\u5165 str&#xff1b;\u8bfb\u5230\u7a7a\u683c\u540e\u505c\u6b62&#xff0c;\u5f97\u5230 &#034;hello&#034;\u3002\u518d\u6b21\u8bfb\u53d6\u65f6&#xff0c;\u4f1a\u4ece w \u5f00\u59cb&#xff0c;\u8bfb\u5230\u6362\u884c\u540e\u505c\u6b62&#xff0c;\u5f97\u5230 &#034;world&#034;\u3002\u8fd9\u91cc\u7684\u7a7a\u683c\u6216\u6362\u884c\u5df2\u7ecf\u88ab get() \u53d6\u8d70&#xff0c;\u53ea\u662f\u6ca1\u6709\u52a0\u5165\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u51fd\u6570\u6700\u540e\u8fd4\u56de in \u7684\u5f15\u7528&#xff0c;\u662f\u4e3a\u4e86\u652f\u6301\u8fde\u7eed\u8f93\u5165&#xff0c;\u4f8b\u5982 cin &gt;&gt; str1 &gt;&gt; str2&#xff1a;\u524d\u4e00\u6b21\u8c03\u7528\u8fd4\u56de\u7684\u8f93\u5165\u6d41&#xff0c;\u53ef\u4ee5\u7ee7\u7eed\u4ea4\u7ed9\u4e0b\u4e00\u6b21\u8c03\u7528\u4f7f\u7528\u3002<\/p>\n<p>\u4e0d\u8fc7&#xff0c;\u8fd9\u4efd\u4ee3\u7801\u6709\u4e00\u4e2a\u5fc5\u987b\u6307\u51fa\u7684\u95ee\u9898&#xff1a;\u5b83\u6ca1\u6709\u5904\u7406\u6587\u4ef6\u7ed3\u675f&#xff08;EOF&#xff09;\u3002in.get() \u7684\u8fd4\u56de\u503c\u672c\u6765\u53ef\u4ee5\u8868\u793a\u201c\u5df2\u7ecf\u6ca1\u6709\u5b57\u7b26\u53ef\u8bfb\u201d&#xff1b;\u4ee3\u7801\u5374\u7acb\u523b\u628a\u5b83\u5b58\u8fdb char ch&#xff0c;\u968f\u540e\u53ea\u68c0\u67e5\u7a7a\u683c\u548c\u6362\u884c\u3002\u5982\u679c\u8f93\u5165\u5728\u6ca1\u6709\u8fd9\u4e24\u79cd\u5b57\u7b26\u7684\u60c5\u51b5\u4e0b\u7ed3\u675f&#xff0c;\u5faa\u73af\u5c31\u53ef\u80fd\u4e00\u76f4\u8bfb\u4e0b\u53bb\u3002\u56e0\u6b64&#xff0c;\u8fd9\u6bb5\u4ee3\u7801\u53ef\u4ee5\u7528\u6765\u8bf4\u660e\u9010\u5b57\u7b26\u8bfb\u53d6\u548c\u8ffd\u52a0\u7684\u57fa\u672c\u601d\u8def&#xff0c;\u4f46\u535a\u5ba2\u91cc\u4e0d\u80fd\u628a\u5b83\u79f0\u4e3a\u5b8c\u6574\u6b63\u786e\u7684\u5b9e\u73b0\u3002\u8fd8\u6709\u4e00\u70b9&#xff0c;\u5b83\u4e0d\u4f1a\u8df3\u8fc7\u5f00\u5934\u7684\u7a7a\u683c&#xff0c;\u5f00\u5934\u5c31\u662f\u7a7a\u683c\u65f6&#xff0c;\u672c\u6b21\u8bfb\u53d6\u4f1a\u5f97\u5230\u7a7a\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u4ee3\u7801\u5757&#xff1a;<\/p>\n<p>istream&amp; operator&gt;&gt;(istream&amp; in, string&amp; str)<br \/>\n{<br \/>\nstr.clear();<br \/>\nchar ch &#061; in.get();<br \/>\nwhile (ch !&#061; &#039;\\\\n&#039; &amp;&amp; ch !&#061; &#039; &#039;)<br \/>\n{<br \/>\nstr &#043;&#061; ch;<br \/>\nch &#061; in.get();<br \/>\n}<\/p>\n<p>return in;<br \/>\n}<\/p>\n<p>\u4f46\u662f\u8fd8\u6709\u4e2a\u95ee\u9898&#xff1a;\u6211\u4eec\u8fd9\u4e2astr\u662f\u8981\u6269\u5bb9\u7684\u554a&#xff01;\u6269\u5bb9\u662f\u8981\u6d88\u8017\u65f6\u95f4\u7684\u554a&#xff0c;\u5982\u679c\u6211\u8f93\u5165\u4e00\u5927\u4e32\u5b57\u7b26\u5230str\u4e2d&#xff0c;\u90a3\u4e0d\u5c31\u8981\u4e0d\u65ad\u7684\u6269\u5bb9\u5417&#xff1f;\u8fd9\u65f6\u6709\u4eba\u4f1a\u60f3&#xff1a;\u90a3\u6211\u7528reserve\u6765\u63d0\u524d\u5f00\u597d\u7a7a\u95f4\u4e0d\u5c31\u884c\u4e86\u5417&#xff1f;\u90a3\u4e48\u8981\u5f00\u591a\u5927\u5462&#xff1f;\u5f00100\u7684\u8bdd&#xff0c;\u5982\u679c\u6211\u5c31\u8f93\u5165\u4e00\u4e2a\u5b57\u7b26&#xff0c;\u90a3\u5269\u4e0b\u768499\u4e2a\u7a7a\u95f4\u4e0d\u5c31\u6d6a\u8d39\u4e86\u5417&#xff1f;\u90a3\u4e48\u5c31\u6ca1\u6709\u66f4\u597d\u7684\u529e\u6cd5\u4e86\u5417&#xff1f;\u6709\u7684&#xff0c;\u5982\u4ee3\u7801\u6240\u793a&#xff1a;<\/p>\n<p>istream&amp; operator&gt;&gt;(istream&amp; in, string&amp; str)<br \/>\n{<br \/>\n    str.clear();<\/p>\n<p>    char buffer[128];<br \/>\n    int i &#061; 0;<br \/>\n    int ch &#061; in.get();<br \/>\n    while (ch !&#061; std::char_traits&lt;char&gt;::eof()&amp;&amp; ch !&#061; &#039;\\\\n&#039;&amp;&amp; ch !&#061; &#039; &#039;)<br \/>\n    {<br \/>\n        buffer[i&#043;&#043;] &#061; static_cast&lt;char&gt;(ch);<\/p>\n<p>        \/\/ \u6512\u591f 127 \u4e2a\u5b57\u7b26&#xff0c;\u7559\u51fa\u6700\u540e\u4e00\u4e2a\u4f4d\u7f6e\u653e &#039;\\\\0&#039;<br \/>\n        if (i &#061;&#061; 127)<br \/>\n        {<br \/>\n            buffer[i] &#061; &#039;\\\\0&#039;;<br \/>\n            str &#043;&#061; buffer;<br \/>\n            i &#061; 0;<br \/>\n        }<\/p>\n<p>        ch &#061; in.get();<br \/>\n    }<\/p>\n<p>    \/\/ \u8f93\u5165\u7ed3\u675f\u65f6&#xff0c;\u53ef\u80fd\u8fd8\u6709\u4e0d\u8db3 127 \u4e2a\u5b57\u7b26\u6ca1\u8ffd\u52a0<br \/>\n    if (i &gt; 0)<br \/>\n    {<br \/>\n        buffer[i] &#061; &#039;\\\\0&#039;;<br \/>\n        str &#043;&#061; buffer;<br \/>\n    }<\/p>\n<p>    return in;<br \/>\n}<\/p>\n<p>\u6211\u4eec\u901a\u8fc7buffer\u8fd9\u4e2a\u5b57\u7b26\u6570\u7ec4\u6765\u5b58\u50a8\u8f93\u5165\u7684\u5b57\u7b26&#xff0c;\u5f53\u8f93\u5165\u7684\u6570\u636e\u6ee1\u8db3\u4e00\u5b9a\u7684\u6761\u4ef6\u65f6&#xff0c;\u5c31\u52a0\u5165\u5230str\u4e2d&#xff0c;\u5c31\u53ef\u4ee5\u907f\u514d\u591a\u6b21\u6269\u5bb9\u7684\u95ee\u9898\u4e86\u3002<\/p>\n<h3>9.\u91cd\u8f7d&#043;\u51fd\u6570<\/h3>\n<p>\u8fd9\u4e2a\u4e5f\u6bd4\u8f83\u7b80\u5355&#xff0c;\u76f4\u63a5\u770b\u4ee3\u7801\u5373\u53ef&#xff1a;<\/p>\n<p>string operator&#043; (const string&amp; lhs, const string&amp; rhs)<br \/>\n{<br \/>\nstring tmp(lhs);<br \/>\ntmp &#043;&#061; rhs;<\/p>\n<p>return tmp;<br \/>\n}<br \/>\nstring operator&#043; (const string&amp; lhs, const char* rhs)<br \/>\n{<br \/>\nstring tmp(lhs);<br \/>\ntmp &#043;&#061; rhs;<\/p>\n<p>return tmp;<br \/>\n}<br \/>\nstring operator&#043; (const char* lhs, const string&amp; rhs)<br \/>\n{<br \/>\nstring tmp(lhs);<br \/>\ntmp &#043;&#061; rhs;<\/p>\n<p>return tmp;<br \/>\n}<\/p>\n<h3>10.\u4ea4\u6362\u4e0e\u53cd\u8f6c\u51fd\u6570<\/h3>\n<p>\u4ea4\u6362\u51fd\u6570&#xff0c;\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u7528\u5e93\u91cc\u9762\u7684&#xff0c;\u5982\u4ee3\u7801\u6240\u793a&#xff1a;<\/p>\n<p>void string::swap(string&amp; str)<br \/>\n{<br \/>\nstd::swap(_str, str._str);<br \/>\nstd::swap(_size, str._size);<br \/>\nstd::swap(_capacity, str._capacity);<br \/>\n}<\/p>\n<p>\u53cd\u8f6c\u51fd\u6570&#xff0c;\u6211\u4eec\u5b9e\u73b0\u8fed\u4ee3\u5668\u7248\u7684\u5373\u53ef&#xff1a;<\/p>\n<p>void string::reverse(iterator begin, iterator end)<br \/>\n{<br \/>\niterator left &#061; begin, right &#061; end &#8211; 1;<\/p>\n<p>while (left &lt; right)<br \/>\n{<br \/>\nstd::swap(*left, *right);<br \/>\nleft&#043;&#043;;<br \/>\nright&#8211;;<br \/>\n}<br \/>\n}<\/p>\n<h3>11.\u4f18\u5316\u90e8\u5206<\/h3>\n<p>\u5176\u5b9e\u6709\u4e86\u8fd9\u4e2a\u4ea4\u6362\u51fd\u6570\u540e&#xff0c;\u6211\u4eec\u7684\u62f7\u8d1d\u6784\u9020\u7b49\u51fd\u6570\u5c31\u53ef\u4ee5\u4f18\u5316\u4e86&#xff0c;\u5982\u4e0b&#xff1a;<\/p>\n<p>string(const string&amp; str)<br \/>\n{<br \/>\nstring tmp(str);<br \/>\nswap(tmp);<br \/>\n}<\/p>\n<p>string&amp; operator&#061;(const string&amp; str)<br \/>\n{<br \/>\nif (this !&#061; &amp;str)<br \/>\n{<br \/>\nstring tmp(str);<br \/>\nswap(tmp);<br \/>\n}<br \/>\nreturn *this;<br \/>\n}<\/p>\n<p>\u4e0d\u8fc7&#xff0c;\u62f7\u8d1d\u6784\u9020\u51fd\u6570\u91cc\u8fd8\u6709\u4e00\u4e2a\u524d\u63d0\u8981\u68c0\u67e5&#xff1a;\u5f53\u524d\u5bf9\u8c61\u7684\u6210\u5458\u5728 swap(tmp) \u524d\u662f\u5426\u5df2\u7ecf\u521d\u59cb\u5316\u3002<\/p>\n<p style=\"background-color:transparent\">\u62f7\u8d1d\u6784\u9020\u662f\u600e\u4e48\u5de5\u4f5c\u7684&#xff1f;<\/p>\n<p>\u5047\u8bbe\u8981\u6839\u636e str \u6784\u9020\u4e00\u4e2a\u65b0\u5bf9\u8c61&#xff1a;<\/p>\n<li>string tmp(str._str) \u5148\u8c03\u7528 const char* \u6784\u9020\u51fd\u6570&#xff0c;\u7533\u8bf7\u5185\u5b58&#xff0c;\u590d\u5236 str \u7684\u5b57\u7b26\u5185\u5bb9\u3002tmp \u6b64\u65f6\u6709\u81ea\u5df1\u72ec\u7acb\u7684\u4e00\u4efd\u6570\u636e\u3002<\/li>\n<li>swap(tmp) \u628a tmp \u7684 _str\u3001_size\u3001_capacity \u4ea4\u6362\u7ed9\u5f53\u524d\u6b63\u5728\u6784\u9020\u7684\u5bf9\u8c61\u3002<\/li>\n<li>tmp \u79bb\u5f00\u4f5c\u7528\u57df\u5e76\u6790\u6784&#xff0c;\u91ca\u653e\u5b83\u5728\u4ea4\u6362\u540e\u62ff\u5230\u7684\u8d44\u6e90\u3002<\/li>\n<p>\u95ee\u9898\u51fa\u5728\u7b2c 2 \u6b65&#xff1a;**\u5f53\u524d\u5bf9\u8c61\u521a\u8fdb\u5165\u62f7\u8d1d\u6784\u9020\u51fd\u6570\u65f6&#xff0c;\u6210\u5458\u4e0d\u4f1a\u56e0\u4e3a\u4f60\u8981\u8c03\u7528 swap \u5c31\u81ea\u52a8\u53d8\u6210\u7a7a\u5b57\u7b26\u4e32\u3002**\u5982\u679c _str\u3001_size\u3001_capacity \u6ca1\u6709\u7c7b\u5185\u9ed8\u8ba4\u503c&#xff0c;\u4e5f\u6ca1\u6709\u5199\u5728\u521d\u59cb\u5316\u5217\u8868\u91cc&#xff0c;swap \u5c31\u4f1a\u8bfb\u53d6\u672a\u521d\u59cb\u5316\u7684\u6210\u5458&#xff1b;\u4e4b\u540e tmp \u8fd8\u53ef\u80fd\u5c1d\u8bd5\u91ca\u653e\u4e00\u4e2a\u65e0\u6548\u6307\u9488\u3002<\/p>\n<p>\u56e0\u6b64&#xff0c;\u5047\u8bbe\u4f60\u7684\u7c7b\u6ca1\u6709\u7ed9\u6210\u5458\u8bbe\u7f6e\u9ed8\u8ba4\u503c&#xff0c;\u81f3\u5c11\u8981\u5148\u628a\u5f53\u524d\u5bf9\u8c61\u521d\u59cb\u5316\u4e3a\u7a7a\u72b6\u6001&#xff1a;<\/p>\n<p>\u5982\u679c\u4f60\u5df2\u7ecf\u5728\u7c7b\u91cc\u5199\u4e86 _str &#061; nullptr\u3001_size &#061; 0\u3001_capacity &#061; 0 \u8fd9\u6837\u7684\u6210\u5458\u9ed8\u8ba4\u503c&#xff0c;\u5c31\u4e0d\u5fc5\u91cd\u590d\u5199\u8fd9\u4efd\u521d\u59cb\u5316\u5217\u8868&#xff0c;\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8fd9\u4e48\u5199&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"153\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260925112522-6ab65a228276c.png\" width=\"618\" \/><\/p>\n<p style=\"background-color:transparent\">\u8d4b\u503c\u8fd0\u7b97\u7b26\u662f\u600e\u4e48\u5de5\u4f5c\u7684&#xff1f;<\/p>\n<p>\u8d4b\u503c\u65f6&#xff0c;\u5f53\u524d\u5bf9\u8c61\u672c\u6765\u5c31\u5df2\u7ecf\u6784\u9020\u597d\u4e86&#xff0c;\u56e0\u6b64\u53ef\u4ee5\u76f4\u63a5\u521b\u5efa tmp \u518d\u4ea4\u6362\u3002\u4ea4\u6362\u540e&#xff0c;\u5f53\u524d\u5bf9\u8c61\u5f97\u5230\u65b0\u5185\u5bb9&#xff0c;tmp \u62ff\u8d70\u5f53\u524d\u5bf9\u8c61\u7684\u65e7\u5185\u5bb9&#xff1b;\u51fd\u6570\u7ed3\u675f\u65f6&#xff0c;tmp \u7684\u6790\u6784\u51fd\u6570\u8d1f\u8d23\u91ca\u653e\u65e7\u5185\u5bb9\u3002if (this !&#061; &amp;str) \u5219\u907f\u514d\u7ed9\u81ea\u5df1\u8d4b\u503c\u65f6\u767d\u505a\u4e00\u6b21\u590d\u5236\u3002<\/p>\n<h3>12.\u5199\u65f6\u62f7\u8d1d<\/h3>\n<p>\u5199\u65f6\u62f7\u8d1d\u53ef\u4ee5\u7406\u89e3\u6210&#xff1a;\u590d\u5236\u5b57\u7b26\u4e32\u65f6\u5148\u4e0d\u590d\u5236\u5b57\u7b26&#xff0c;\u7b49\u67d0\u4e2a\u5bf9\u8c61\u771f\u7684\u8981\u4fee\u6539\u5b57\u7b26\u65f6&#xff0c;\u518d\u7ed9\u5b83\u5355\u72ec\u590d\u5236\u4e00\u4efd\u3002<\/p>\n<p>\u62ff\u4f60\u7684 string \u7c7b\u4e3e\u4f8b\u3002\u5047\u8bbe a \u7684\u5185\u5bb9\u662f &#034;abc&#034;&#xff0c;\u7136\u540e\u6267\u884c b &#061; a\u3002<\/p>\n<p>\u666e\u901a\u7684\u6df1\u62f7\u8d1d\u4f1a\u7acb\u523b\u4e3a b \u7533\u8bf7\u65b0\u7a7a\u95f4&#xff0c;\u628a a \u7684 &#034;abc&#034; \u590d\u5236\u8fc7\u53bb\u3002\u6b64\u65f6\u4e24\u4e2a\u5bf9\u8c61\u5404\u6709\u4e00\u4efd\u6570\u636e\u3002\u800c\u5199\u65f6\u62f7\u8d1d\u4f1a\u5148\u8ba9 a \u548c b \u5171\u7528\u540c\u4e00\u4efd &#034;abc&#034;&#xff0c;\u5e76\u8bb0\u5f55\u201c\u73b0\u5728\u6709 2 \u4e2a\u5bf9\u8c61\u5728\u7528\u8fd9\u4efd\u6570\u636e\u201d\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u5206\u4e24\u79cd\u60c5\u51b5&#xff1a;<\/p>\n<ul>\n<li>\u53ea\u8bfb\u53d6&#xff1a;\u4f8b\u5982\u67e5\u770b a\u3001b \u7684\u5185\u5bb9\u3002\u8c01\u4e5f\u6ca1\u6539\u6570\u636e&#xff0c;\u5b83\u4eec\u5c31\u53ef\u4ee5\u7ee7\u7eed\u5171\u7528&#xff0c;\u4e0d\u9700\u8981\u590d\u5236\u5b57\u7b26\u3002<\/li>\n<li>\u51c6\u5907\u4fee\u6539&#xff1a;\u4f8b\u5982\u628a b[0] \u6539\u6210 &#039;x&#039;\u3002\u5982\u679c\u76f4\u63a5\u5728\u5171\u7528\u7684\u6570\u636e\u4e0a\u6539&#xff0c;a \u4e5f\u4f1a\u8ddf\u7740\u53d8\u6210 &#034;xbc&#034;&#xff0c;\u8fd9\u663e\u7136\u4e0d\u5bf9\u3002\u6240\u4ee5\u4fee\u6539\u524d&#xff0c;\u5148\u4e3a b \u590d\u5236\u4e00\u4efd &#034;abc&#034;&#xff0c;\u8ba9 b \u8131\u79bb\u5171\u4eab&#xff1b;\u7136\u540e\u53ea\u4fee\u6539 b \u7684\u90a3\u4efd\u3002\u6700\u7ec8 a \u662f &#034;abc&#034;&#xff0c;b \u662f &#034;xbc&#034;\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u91cc\u7684\u201c\u5199\u65f6\u201d&#xff0c;\u6307\u7684\u662f\u4fee\u6539\u6570\u636e\u4e4b\u524d\u3002\u5982\u679c\u5df2\u7ecf\u628a\u5171\u7528\u7684\u5b57\u7b26\u6539\u4e86&#xff0c;\u518d\u53bb\u590d\u5236&#xff0c;\u5c31\u665a\u4e86\u3002<\/p>\n<p>\u5b9e\u73b0\u65f6\u901a\u5e38\u8981\u6709\u4e00\u4e2a\u5f15\u7528\u8ba1\u6570&#xff0c;\u8868\u793a\u540c\u4e00\u4efd\u5b57\u7b26\u6570\u636e\u6b63\u5728\u88ab\u591a\u5c11\u4e2a string \u5bf9\u8c61\u4f7f\u7528\u3002\u590d\u5236\u5bf9\u8c61\u65f6&#xff0c;\u8ba1\u6570\u52a0\u4e00&#xff1b;\u5bf9\u8c61\u6790\u6784\u6216\u8131\u79bb\u5171\u4eab\u65f6&#xff0c;\u8ba1\u6570\u51cf\u4e00&#xff1b;\u51cf\u5230\u96f6&#xff0c;\u624d\u91ca\u653e\u8fd9\u4efd\u5b57\u7b26\u6570\u636e\u3002\u6267\u884c append\u3001erase\u3001\u4fee\u6539\u67d0\u4e2a\u5b57\u7b26\u7b49\u64cd\u4f5c\u4e4b\u524d&#xff0c;\u90fd\u8981\u5224\u65ad&#xff1a;\u5982\u679c\u6570\u636e\u53ea\u6709\u81ea\u5df1\u5728\u7528&#xff0c;\u5c31\u76f4\u63a5\u6539&#xff1b;\u5982\u679c\u6709\u591a\u4e2a\u5bf9\u8c61\u5171\u7528&#xff0c;\u5c31\u5148\u590d\u5236\u518d\u6539\u3002<\/p>\n<p>\u5b83\u548c\u4f60\u4e0a\u4e00\u6bb5\u4ee3\u7801\u7684\u533a\u522b\u5728\u4e8e&#xff1a;string tmp(str._str) \u5f53\u573a\u5c31\u590d\u5236\u4e86\u5b57\u7b26&#xff0c;\u5c5e\u4e8e\u6df1\u62f7\u8d1d&#xff1b;\u5199\u65f6\u62f7\u8d1d\u5728\u8fd9\u4e00\u6b65\u53ea\u5171\u4eab\u6570\u636e&#xff0c;\u771f\u6b63\u7684\u5b57\u7b26\u590d\u5236\u63a8\u8fdf\u5230\u4fee\u6539\u65f6\u3002\u597d\u5904\u662f\u201c\u590d\u5236\u5f88\u591a\u6b21\u3001\u4f46\u5f88\u5c11\u4fee\u6539\u201d\u65f6\u80fd\u7701\u4e0b\u590d\u5236\u5f00\u9500&#xff1b;\u4ee3\u4ef7\u662f\u6bcf\u6b21\u4fee\u6539\u524d\u90fd\u8981\u68c0\u67e5\u662f\u5426\u5171\u4eab&#xff0c;\u800c\u4e14\u50cf operator[] \u8fd4\u56de\u53ef\u4fee\u6539\u7684 char&amp; \u8fd9\u79cd\u63a5\u53e3\u4f1a\u8ba9\u5b9e\u73b0\u53d8\u590d\u6742\u2014\u2014\u5f15\u7528\u4ea4\u51fa\u53bb\u4e4b\u540e&#xff0c;\u7c7b\u5c31\u4e0d\u4e00\u5b9a\u80fd\u62e6\u4f4f\u4f7f\u7528\u8005\u76f4\u63a5\u6539\u5b57\u7b26\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1320\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260925112522-6ab65a229db6c.png\" width=\"1500\" \/><\/p>\n<\/p>\n<p>\u603b\u7ed3&#xff1a;\u672c\u6587\u901a\u8fc7\u6a21\u62df\u5b9e\u73b0 string \u7c7b&#xff0c;\u68b3\u7406\u4e86\u5b57\u7b26\u4e32\u7684\u6784\u9020\u3001\u6269\u5bb9\u3001\u63d2\u5165\u3001\u5220\u9664\u3001\u67e5\u627e\u548c\u8f93\u5165\u8f93\u51fa\u7b49\u64cd\u4f5c\u3002\u91cd\u70b9\u5728\u4e8e\u7ef4\u62a4\u597d\u5b57\u7b26\u6570\u7ec4\u3001_size \u548c _capacity \u7684\u5173\u7cfb&#xff0c;\u5e76\u7406\u89e3\u62f7\u8d1d\u4ea4\u6362\u4e0e\u5199\u65f6\u62f7\u8d1d\u5404\u81ea\u5982\u4f55\u7ba1\u7406\u5b57\u7b26\u4e32\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7bc7\u76ee\u6807&#xff1a;\u638c\u63e1string\u7c7b\u7684\u90e8\u5206\u63a5\u53e3\u7684\u5b9e\u73b0\u4e00. string\u7c7b\u7684\u5e95\u5c42\u5b9e\u73b01.\u6784\u9020\u51fd\u6570\u9996\u5148\u6211\u4eec\u4e3a\u4e86\u4e0etsd\u5e93\u91cc\u9762\u7684string \u9694\u79bb\u4e00\u4e0b&#xff0c;\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u81ea\u5df1\u7684\u547d\u540d\u7a7a\u95f4&#xff0c;\u6211\u7684\u5c31\u662fkong\u4e86&#xff0c;C \u4e2d\u7684\u5b57\u7b26\u4e32\u672c\u8d28\u4e0a\u662f\u7531\u5b57\u7b26\u6570\u7ec4\u6784\u6210\u7684&#xff0c;\u800c C \u98ce\u683c\u5b57\u7b26\u4e32\u5e95\u5c42\u5c31\u662f&#xff1a;char*\u6240\u4ee5\u8fd9\u4e2a\u6a21\u62dfstring \u7c7b\u7684\u5927\u81f4\u6846\u67b6\u4e3a:\u5728string\u7c7b\u4e2d:#pragma once<br \/>\n#define _CRT_SECURE_<\/p>\n","protected":false},"author":2,"featured_media":110049,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[11653,55,190,427],"topic":[],"class_list":["post-110055","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-11653","tag-c","tag-190","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u516b):string\u7c7b\u7684\u5e95\u5c42\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/110055.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u516b):string\u7c7b\u7684\u5e95\u5c42\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u672c\u7bc7\u76ee\u6807&#xff1a;\u638c\u63e1string\u7c7b\u7684\u90e8\u5206\u63a5\u53e3\u7684\u5b9e\u73b0\u4e00. string\u7c7b\u7684\u5e95\u5c42\u5b9e\u73b01.\u6784\u9020\u51fd\u6570\u9996\u5148\u6211\u4eec\u4e3a\u4e86\u4e0etsd\u5e93\u91cc\u9762\u7684string \u9694\u79bb\u4e00\u4e0b&#xff0c;\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u81ea\u5df1\u7684\u547d\u540d\u7a7a\u95f4&#xff0c;\u6211\u7684\u5c31\u662fkong\u4e86&#xff0c;C \u4e2d\u7684\u5b57\u7b26\u4e32\u672c\u8d28\u4e0a\u662f\u7531\u5b57\u7b26\u6570\u7ec4\u6784\u6210\u7684&#xff0c;\u800c C \u98ce\u683c\u5b57\u7b26\u4e32\u5e95\u5c42\u5c31\u662f&#xff1a;char*\u6240\u4ee5\u8fd9\u4e2a\u6a21\u62dfstring \u7c7b\u7684\u5927\u81f4\u6846\u67b6\u4e3a:\u5728string\u7c7b\u4e2d:#pragma once #define _CRT_SECURE_\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/110055.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-25T11:25:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260925112518-6ab65a1ee1e22.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/110055.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/110055.html\",\"name\":\"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u516b):string\u7c7b\u7684\u5e95\u5c42\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-25T11:25:24+00:00\",\"dateModified\":\"2026-09-25T11:25:24+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/110055.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/110055.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/110055.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u516b):string\u7c7b\u7684\u5e95\u5c42\u5b9e\u73b0\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u516b):string\u7c7b\u7684\u5e95\u5c42\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/110055.html","og_locale":"zh_CN","og_type":"article","og_title":"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u516b):string\u7c7b\u7684\u5e95\u5c42\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u672c\u7bc7\u76ee\u6807&#xff1a;\u638c\u63e1string\u7c7b\u7684\u90e8\u5206\u63a5\u53e3\u7684\u5b9e\u73b0\u4e00. string\u7c7b\u7684\u5e95\u5c42\u5b9e\u73b01.\u6784\u9020\u51fd\u6570\u9996\u5148\u6211\u4eec\u4e3a\u4e86\u4e0etsd\u5e93\u91cc\u9762\u7684string \u9694\u79bb\u4e00\u4e0b&#xff0c;\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u81ea\u5df1\u7684\u547d\u540d\u7a7a\u95f4&#xff0c;\u6211\u7684\u5c31\u662fkong\u4e86&#xff0c;C \u4e2d\u7684\u5b57\u7b26\u4e32\u672c\u8d28\u4e0a\u662f\u7531\u5b57\u7b26\u6570\u7ec4\u6784\u6210\u7684&#xff0c;\u800c C \u98ce\u683c\u5b57\u7b26\u4e32\u5e95\u5c42\u5c31\u662f&#xff1a;char*\u6240\u4ee5\u8fd9\u4e2a\u6a21\u62dfstring \u7c7b\u7684\u5927\u81f4\u6846\u67b6\u4e3a:\u5728string\u7c7b\u4e2d:#pragma once #define _CRT_SECURE_","og_url":"https:\/\/www.wsisp.com\/helps\/110055.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-25T11:25:24+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260925112518-6ab65a1ee1e22.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"10 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/110055.html","url":"https:\/\/www.wsisp.com\/helps\/110055.html","name":"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u516b):string\u7c7b\u7684\u5e95\u5c42\u5b9e\u73b0 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-25T11:25:24+00:00","dateModified":"2026-09-25T11:25:24+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/110055.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/110055.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/110055.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C++\u8bed\u8a00\u539f\u7406\u4e0e\u5b9e\u8df5(\u516b):string\u7c7b\u7684\u5e95\u5c42\u5b9e\u73b0"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/110055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=110055"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/110055\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/110049"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=110055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=110055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=110055"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=110055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}