{"id":1082,"date":"2026-04-25T22:15:58","date_gmt":"2026-04-25T14:15:58","guid":{"rendered":"http:\/\/wordpress.fangt.online\/?p=1082"},"modified":"2026-05-17T01:02:10","modified_gmt":"2026-05-16T17:02:10","slug":"%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%b8%b8%e7%94%a8%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"http:\/\/wordpress.fangt.online\/index.php\/2026\/04\/25\/%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%b8%b8%e7%94%a8%e5%8a%9f%e8%83%bd\/","title":{"rendered":"\u5b57\u7b26\u4e32\u5e38\u7528\u529f\u80fd"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u521d\u59cb\u5316\u64cd\u4f5c<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u5e38\u89c1\u64cd\u4f5c<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s1; \/\/ s1 = \"\"\nstring s2 = string(); \/\/ s2 = \"\"\nstring s3 = \"Hello\"; \/\/ \u62f7\u8d1d\u521d\u59cb\u5316\u4e3a\"hello\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u6784\u9020\u521d\u59cb\u5316<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s1(\"World\"); \/\/ \u76f4\u63a5\u521d\u59cb\u5316\nstring s2(5, 'A'); \/\/ \"AAAAA\"\nstring s3(10, '*');  \/\/ \"**********\"         <\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5217\u8868\u521d\u59cb\u5316<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s1{'R'}; \/\/ \"R\"\nstring s2{'a','b','c','\\0'}; \/\/ \"abc\"\nstring s3{\"C++\"}; \/\/ \"C++\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u8bbf\u95ee\u64cd\u4f5c<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e0b\u6807\u8bbf\u95ee []<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"hello\";\nchar c = s&#91;1]; \/\/ 'e'\nchar c2 = s&#91;10]; \/\/ \u8d8a\u754c\u4e0d\u629b\u5f02\u5e38\uff0c\u4f46\u6709\u98ce\u9669\u5d29\u6e83<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b89\u5168\u8bbf\u95ee at()<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"hello\";\nchar c = s.at(1); \/\/ 'e'\nchar c2 = s.at(10); \/\/ \u629b\u5f02\u5e38<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u9996\u5c3e\u8bbf\u95ee front() back()<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"hello\";\nchar c = s.front(); \/\/ 'h'\nchar c2 = s.back(); \/\/ 'o'<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u8fed\u4ee3\u5668\u8bbf\u95ee begin() end()<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"hello\";\nauto it1 = s.begin();\ncout&lt;&lt;*it1; \/\/ 'h'<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5bb9\u91cf empty() size() length()<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"hello\";\nbool f = s.empty(); \/\/ \u7a7atrue \u975e\u7a7afalse\nint a = s.size(); \/\/ 5 \u5927\u5c0f\nint b = s.length(); \/\/ 5 \u957f\u5ea6\uff0c\u4e0esize\u4f5c\u7528\u76f8\u540c<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u6570\u636e\u64cd\u4f5c<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u6e05\u7a7a clear()<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"hello\";\ns.clear();\ncout&lt;&lt;s.size(); \/\/ 0\uff0c\u5b57\u7b26\u4e32\u4e2d\u4ec0\u4e48\u90fd\u6ca1\u6709\u4e86\uff0c\u5927\u5c0f\u4e3a0<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u66f4\u6539\u5927\u5c0f resize()<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"hello\";\ns.resize(3); \/\/ \"hel\" \u622a\u65ad\ns.resize(8); \/\/ \"hel\"+5\u4e2a'\\0'\ncout&lt;&lt;s.size(); \/\/ 8\ns.resize(10,'k'); \/\/ \"helkkkkkkk\" \u7a7a\u5b57\u7b26\u586b\u5145'k'<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u63d2\u5165 insert()<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"hello\";\ns.insert(2,\"xyz\"); \/\/ \"hexyzllo\" 2\u4e0b\u6807\u4f4d\u7f6e\u63d2\u5165xyz<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u589e\u52a0\u3001\u5220\u9664\u672b\u5c3e\u5b57\u7b26 push_back() pop_back()<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"hello\";\ns.push_back('A'); \/\/ \"helloA\"\n\nstring s = \"hello\";\ns.pop_back(); \/\/ \"hell\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u8ffd\u52a0\u591a\u4e2a\u5185\u5bb9 append() +=<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"hello\";\ns.append(\"world\"); \/\/ \"helloworld\"\ns.append(5,\"!\"); \/\/ \"helloworld!!!!!\"\n\ns+=\"~~~\"; \/\/ \"helloworld!!!!!~~~\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u5220\u9664\u5b57\u7b26 erase()<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"helloworld\";\ns.erase(5,3); \/\/ \"hellold\"\u4ece5\u4e0b\u6807\u5220\u96643\u4e2a\u5b57\u7b26<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u66ff\u6362\u5b57\u7b26 replace()<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"hello world\";\ns.replace(6,5,\"C++\"); \/\/ \"hello C++\"\u4ece6\u4e0b\u6807\u5f00\u59cb\u76845\u4e2a\u5b57\u7b26\u66ff\u6362\u6210C++<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u63d0\u53d6\u5b57\u4e32 substr()<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"hello world\";\nstring str1 = s.substr(7); \/\/ \"orld\" \u4ece\u4e0b\u68077\u5f00\u59cb\u5230\u6700\u540e\nstring str2 = s.substr(4,3); \/\/ \"o w\" \u4ece\u4e0b\u68074\u5f00\u59cb\u76843\u4e2a\u5b57\u7b26<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u5012\u5e8f reverse() \u975e\u5b57\u7b26\u4e32\u72ec\u6709\u7528\u6cd5<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"12345\";\nreverse(s.begin(),s.end());\ncout&lt;&lt;s; \/\/ \"54321\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u6bd4\u8f83 compare()<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\u975e\u590d\u6742\u8981\u6c42\u7684\u60c5\u51b5\u4e0b\u5efa\u8bae\u76f4\u63a5\u4f7f\u7528\u5173\u7cfb\u8fd0\u7b97\u7b26<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u7684\u7c7b\u578b\u8f6c\u6362<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u8f6c\u6570\u503c<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s1 = \"123\";\nint a = stoi(s1); \/\/ \u5c06s1\u8f6c\u6362\u6210\u6570\u5b57123\u5e76\u8d4b\u503c\u7ed9a\n\nstring s2 = \"12345678912345\";\nlong long b = stoll(s2); \/\/ \u5c06s2\u8f6c\u6362\u6210\u6570\u5b5712345678912345\u5e76\u8d4b\u503c\u7ed9b\n\nstring s3 = \"123.456\";\nfloat c = stof(s3); \/\/ \u5c06s3\u8f6c\u6362\u6210\u6570\u5b57123.456\u5e76\u8d4b\u503c\u7ed9c\n\nstring s4 = \"-123.456\";\ndouble d = stod(s4); \/\/ \u5c06s4\u8f6c\u6362\u6210\u6570\u5b57-123.456\u5e76\u8d4b\u503c\u7ed9d<\/code><\/pre>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">\u9ad8\u7ea7\u7528\u6cd5\u81ea\u884c\u4e86\u89e3\uff08\u9501\u5b9a\u6807\u8bb0\u3001\u81ea\u52a8\u8f6c\u8fdb\u5236\uff09<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6570\u503c\u8f6c\u5b57\u7b26\u4e32<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>int num = 12345;\nstring s1 = to_string(num); \/\/ \u5c06\u6574\u6570\u8f6c\u6362\u6210\"12345\"\u5e76\u8d4b\u503c\u7ed9s1\n\ndouble pi = 3.14;\nstring s2 = to_string(pi); \/\/ \u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u6210\"3.140000\"\u5e76\u8d4b\u503c\u7ed9s2\uff08\u9ed8\u8ba4\u7cbe\u5ea66\u4f4d\uff09<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b57\u7b26\u4e32\u8f6c\u5b57\u7b26\u6570\u7ec4<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"hello\";\nconst char* c = s.c_str();<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u8865\u5145\uff1a\u5b57\u7b26\u4e32\u67e5\u8be2find()<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u4e0b\u6807\u4f4d\u7f6e\uff0c\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56deunsigned long long\u7684\u6700\u5927\u503c\uff0c\u5982\u679c\u7ed3\u679c\u8d4b\u503c\u7ed9int\u7c7b\u578b\uff0c\u5219\u662f-1 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>string s = \"hello\";\nint a = s.find(\"ll\"); \/\/ \u67e5\u8be2\u5b57\u7b26\u4e32s\u4e2d\u662f\u5426\u5305\u542b\u5b50\u4e32\"ll\"\nint b = s.find('e'); \/\/ \u67e5\u8be2\u5b57\u7b26\u4e32s\u4e2d\u662f\u5426\u5305\u542b\u5b57\u7b26'e'<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b57\u7b26\u4e32\u521d\u59cb\u5316\u64cd\u4f5c \u5e38\u89c1\u64cd\u4f5c \u6784\u9020\u521d\u59cb\u5316 \u5217\u8868\u521d\u59cb\u5316 \u5b57\u7b26\u4e32\u8bbf\u95ee\u64cd\u4f5c \u4e0b\u6807\u8bbf\u95ee [] \u5b89\u5168\u8bbf\u95ee at() \u9996\u5c3e\u8bbf [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-1082","post","type-post","status-publish","format-standard","hentry","category-zl"],"_links":{"self":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts\/1082","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/comments?post=1082"}],"version-history":[{"count":5,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts\/1082\/revisions"}],"predecessor-version":[{"id":1572,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/posts\/1082\/revisions\/1572"}],"wp:attachment":[{"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/media?parent=1082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/categories?post=1082"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wordpress.fangt.online\/index.php\/wp-json\/wp\/v2\/tags?post=1082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}