{"id":90,"date":"2026-03-22T17:13:29","date_gmt":"2026-03-22T09:13:29","guid":{"rendered":"https:\/\/codergodv.xyz\/?p=90"},"modified":"2026-03-22T17:13:29","modified_gmt":"2026-03-22T09:13:29","slug":"c11%e5%85%a5%e9%97%a8%e5%9f%ba%e7%a1%80","status":"publish","type":"post","link":"https:\/\/codergodv.xyz\/index.php\/2026\/03\/22\/c11%e5%85%a5%e9%97%a8%e5%9f%ba%e7%a1%80\/","title":{"rendered":"C++11\u5165\u95e8\u57fa\u7840"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">C++11\u7b80\u4ecb<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u57282003\u5e74C++\u6807\u51c6\u59d4\u5458\u4f1a\u63d0\u4ea4\u4e86\u4e00\u4efd\u6280\u672f\u52d8\u8bef\u8868\uff08\u7b80\u79f0TC1\uff09\uff0c\u4f7f\u5f97C++03\u8fd9\u4e2a\u540d\u5b57\u53d6\u4ee3\u4e86C++98\u6210\u4e3aC++11\u4e4b\u524d\u7684\u6700\u65b0C++\u6807\u51c6\u540d\u79f0\u3002<\/li>\n\n\n\n<li>\u4f46\u7531\u4e8eC++03\u4e3b\u8981\u662f\u5bf9C++98\u6807\u51c6\u4e2d\u7684\u6f0f\u6d1e\u8fdb\u884c\u4fee\u590d\uff0c\u8bed\u8a00\u7684\u6838\u5fc3\u90e8\u5206\u5219\u6ca1\u6709\u6539\u52a8\uff0c\u56e0\u6b64\u4eba\u4eec\u4e60\u60ef\u6027\u7684\u628a\u8fd9\u4e24\u4e2a\u6807\u51c6\u5408\u5e76\u79f0\u4e3aC++98\/03\u6807\u51c6\u3002<\/li>\n\n\n\n<li>\u4eceC++0x\u5230C++11\uff0cC++\u6807\u51c610\u5e74\u78e8\u4e00\u5251\uff0c\u7b2c\u4e8c\u4e2a\u771f\u6b63\u610f\u4e49\u4e0a\u7684\u6807\u51c6\u59d7\u59d7\u6765\u8fdf\u3002\u76f8\u6bd4\u4e8eC++98\/03\uff0cC++11\u5219\u5e26\u6765\u4e86\u6570\u91cf\u53ef\u89c2\u7684\u53d8\u5316\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u7ea6140\u4e2a\u65b0\u7279\u6027\uff0c\u4ee5\u53ca\u5bf9C++03\u6807\u51c6\u4e2d\u7ea6600\u4e2a\u7f3a\u9677\u7684\u4fee\u6b63\uff0c\u8fd9\u4f7f\u5f97C++11\u66f4\u50cf\u662f\u4eceC++98\/03\u4e2d\u5b55\u80b2\u51fa\u7684\u4e00\u79cd\u65b0\u8bed\u8a00\u3002<\/li>\n\n\n\n<li>\u76f8\u6bd4\u8f83\u800c\u8a00\uff0cC++11\u80fd\u66f4\u597d\u5730\u7528\u4e8e\u7cfb\u7edf\u5f00\u53d1\u548c\u5e93\u5f00\u53d1\u3001\u8bed\u8a00\u66f4\u52a0\u6cdb\u534e\u548c\u7b80\u5355\u5316\u3001\u66f4\u52a0\u7a33\u5b9a\u548c\u5b89\u5168\uff0c\u4e0d\u4ec5\u529f\u80fd\u66f4\u5f3a\u5927\uff0c\u800c\u4e14\u80fd\u63d0\u5347\u7a0b\u5e8f\u5458\u7684\u5f00\u53d1\u6548\u7387\uff0c\u516c\u53f8\u5b9e\u9645\u9879\u76ee\u5f00\u53d1\u4e2d\u4e5f\u7528\u5f97\u6bd4\u8f83\u591a\u3002<\/li>\n<\/ul>\n\n\n\n<p>C++11\u589e\u52a0\u7684\u8bed\u6cd5\u7279\u6027\u975e\u5e38\u591a\uff0c\u672c\u7bc7\u535a\u5ba2\u53ea\u8bb2\u89e3\u4e00\u90e8\u5206\u7b80\u5355\u7684\u8bed\u6cd5\uff0c\u540e\u9762\u8fd8\u4f1a\u9646\u7eed\u66f4\u65b0C++11\u7684\u4e00\u4e9b\u91cd\u8981\u8bed\u6cd5\uff0c\u5982\u679c\u60f3\u4e86\u89e3C++11\u7684\u5176\u4ed6\u66f4\u591a\u8bed\u6cd5\u7279\u6027\uff0c\u53ef\u4ee5\u53bbC++\u7684\u5b98\u7f51\uff1ahttps:\/\/en.cppreference.com\/w\/cpp\/11<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u5c0f\u6545\u4e8b\uff1a<\/strong><br>\u2003\u20031998\u5e74\u662fC++\u6807\u51c6\u59d4\u5458\u4f1a\u6210\u7acb\u7684\u7b2c\u4e00\u5e74\uff0c\u672c\u6765\u8ba1\u5212\u4ee5\u540e\u6bcf5\u5e74\u65f6\u95f4\u66f4\u65b0\u4e00\u6b21\u6807\u51c6\uff0cC++\u56fd\u9645\u6807\u51c6\u59d4\u5458\u4f1a\u5728\u7814\u7a76C++03\u7684\u4e0b\u4e00\u4e2a\u7248\u672c\u7684\u65f6\u5019\uff0c\u4e00\u5f00\u59cb\u8ba1\u5212\u662f2007\u5e74\u53d1\u5e03\uff0c\u6240\u4ee5\u6700\u521d\u8fd9\u4e2a\u6807\u51c6\u53ebC++07\u3002<br>\u2003\u2003\u4f46\u662f\u52302006\u5e74\u7684\u65f6\u5019\uff0c\u5b98\u65b9\u89c9\u5f972007\u5e74\u80af\u5b9a\u5b8c\u4e0d\u6210C++07\uff0c\u800c\u4e14\u5b98\u65b9\u89c9\u5f972008\u5e74\u53ef\u80fd\u4e5f\u5b8c\u4e0d\u6210\uff0c\u6700\u540e\u5e72\u8106\u53ebC++0x\uff0cx\u7684\u610f\u601d\u5c31\u662f\u4e0d\u77e5\u9053\u5230\u5e95\u80fd\u572807\u8fd8\u662f08\u8fd8\u662f09\u5e74\u5b8c\u6210\uff0c\u7ed3\u679c2010\u5e74\u7684\u65f6\u5019\u4e5f\u6ca1\u5b8c\u6210\uff0c\u6700\u540e\u57282011\u5e74\u7ec8\u4e8e\u5b8c\u6210\u4e86C++\u6807\u51c6\uff0c\u6700\u7ec8\u5b9a\u540d\u4e3aC++11\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u5316<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>{ }\u7684\u521d\u59cb\u5316<\/p>\n<\/blockquote>\n\n\n\n<p>C++98\u4e2d\uff0c\u6807\u51c6\u5141\u8bb8\u4f7f\u7528\u5927\u62ec\u53f7{}\u5bf9\u6570\u7ec4\u6216\u8005\u7ed3\u6784\u4f53\u5143\u7d20\u8fdb\u884c\u7edf\u4e00\u7684\u5217\u8868\u521d\u59cb\u503c\u8bbe\u5b9a\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>struct Point\n{\n    int _x;\n    int _y;\n};\nint main()\n{\n    \/\/\u4f7f\u7528\u5927\u62ec\u53f7\u5bf9\u6570\u7ec4\u5143\u7d20\u8fdb\u884c\u521d\u59cb\u5316\n    int array1&#91;] = { 1, 2, 3, 4, 5 };\n    int array2&#91;5] = { 0 };\n\n    \/\/\u4f7f\u7528\u5927\u62ec\u53f7\u5bf9\u7ed3\u6784\u4f53\u5143\u7d20\u8fdb\u884c\u521d\u59cb\u5316\n    Point p = { 1, 2 };\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>C++11\u6269\u5927\u4e86\u7528\u5927\u62ec\u53f7\u62ec\u8d77\u6765\u7684\u5217\u8868<code>{\u521d\u59cb\u5316\u5217\u8868}<\/code>\u7684\u4f7f\u7528\u8303\u56f4\uff0c\u4f7f\u5176\u53ef\u7528\u4e8e\u6240\u6709\u7684\u5185\u7f6e\u7c7b\u578b\u548c\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u7c7b\u578b\uff0c\u4f7f\u7528<a href=\"https:\/\/so.csdn.net\/so\/search?q=\u521d\u59cb\u5316\u5217\u8868&amp;spm=1001.2101.3001.7020\">\u521d\u59cb\u5316\u5217\u8868<\/a>\u65f6\uff0c\u53ef\u6dfb\u52a0\u7b49\u53f7\uff0c\u4e5f\u53ef\u4e0d\u6dfb\u52a0\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>struct Point\n{\n    int _x;\n    int _y;\n};\nint main()\n{\n    \/\/\u4f7f\u7528\u5927\u62ec\u53f7\u5bf9\u5185\u7f6e\u7c7b\u578b\u8fdb\u884c\u521d\u59cb\u5316\n    int x1 = { 1 }; \/\/\u53ef\u6dfb\u52a0\u7b49\u53f7\n    int x2{ 2 };    \/\/\u53ef\u4e0d\u6dfb\u52a0\u7b49\u53f7\n\n    \/\/\u4f7f\u7528\u5927\u62ec\u53f7\u5bf9\u6570\u7ec4\u5143\u7d20\u8fdb\u884c\u521d\u59cb\u5316\n    int array1&#91;]{1, 2, 3, 4, 5}; \/\/\u53ef\u4e0d\u6dfb\u52a0\u7b49\u53f7\n    int array2&#91;5]{0};            \/\/\u53ef\u4e0d\u6dfb\u52a0\u7b49\u53f7\n\n    \/\/\u4f7f\u7528\u5927\u62ec\u53f7\u5bf9\u7ed3\u6784\u4f53\u5143\u7d20\u8fdb\u884c\u521d\u59cb\u5316\n    Point p{ 1, 2 }; \/\/\u53ef\u4e0d\u6dfb\u52a0\u7b49\u53f7\n\n    \/\/C++11\u4e2d\u5217\u8868\u521d\u59cb\u5316\u4e5f\u53ef\u4ee5\u7528\u4e8enew\u8868\u8fbe\u5f0f\u4e2d\uff08C++98\u65e0\u6cd5\u521d\u59cb\u5316\uff09\n    int* p1 = new int&#91;4]{0};       \/\/\u4e0d\u53ef\u6dfb\u52a0\u7b49\u53f7\n    int* p2 = new int&#91;4]{1,2,3,4}; \/\/\u4e0d\u53ef\u6dfb\u52a0\u7b49\u53f7\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>\u6ce8\u610f\uff1a<\/strong> \u7528\u5927\u62ec\u53f7\u5bf9new\u8868\u8fbe\u5f0f\u521d\u59cb\u5316\u65f6\u4e0d\u80fd\u52a0\u7b49\u53f7\u3002<\/p>\n\n\n\n<p>\u521b\u5efa\u5bf9\u8c61\u65f6\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u521d\u59cb\u5316\u65b9\u5f0f\u8c03\u7528<a href=\"https:\/\/so.csdn.net\/so\/search?q=\u6784\u9020\u51fd\u6570\u521d\u59cb\u5316&amp;spm=1001.2101.3001.7020\">\u6784\u9020\u51fd\u6570\u521d\u59cb\u5316<\/a>\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Date\n{\npublic:\n    Date(int year, int month, int day)\n        :_year(year)\n        , _month(month)\n        , _day(day)\n    {\n        cout &lt;&lt; \"Date(int year, int month, int day)\" &lt;&lt; endl;\n    }\nprivate:\n    int _year;\n    int _month;\n    int _day;\n};\nint main()\n{\n    \/\/\u4e00\u822c\u8c03\u7528\u6784\u9020\u51fd\u6570\u521b\u5efa\u5bf9\u8c61\u7684\u65b9\u5f0f\n    Date d1(2022, 8, 29);\n\n    \/\/C++11\u652f\u6301\u7684\u5217\u8868\u521d\u59cb\u5316\uff0c\u8fd9\u91cc\u4e5f\u4f1a\u8c03\u7528\u6784\u9020\u51fd\u6570\u521d\u59cb\u5316\n    Date d2 = { 2022, 8, 30 }; \/\/\u53ef\u6dfb\u52a0\u7b49\u53f7\n    Date d3{ 2022, 8, 31 };    \/\/\u53ef\u4e0d\u6dfb\u52a0\u7b49\u53f7\n    return 0;\n}<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>initializer_list\u5bb9\u5668<\/p>\n<\/blockquote>\n\n\n\n<p>C++11\u4e2d\u65b0\u589e\u4e86initializer_list\u5bb9\u5668\uff0c\u8be5\u5bb9\u5668\u6ca1\u6709\u63d0\u4f9b\u8fc7\u591a\u7684\u6210\u5458\u51fd\u6570\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u63d0\u4f9b\u4e86begin\u548cend\u51fd\u6570\uff0c\u7528\u4e8e\u652f\u6301\u8fed\u4ee3\u5668\u904d\u5386\u3002<\/li>\n\n\n\n<li>\u4ee5\u53casize\u51fd\u6570\u652f\u6301\u83b7\u53d6\u5bb9\u5668\u4e2d\u7684\u5143\u7d20\u4e2a\u6570\u3002<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/cdn.codergodv.xyz\/960ccdbe907485d25ba230d12911f71f.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/cdn.codergodv.xyz\/960ccdbe907485d25ba230d12911f71f.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"\/><\/div><\/figure>\n\n\n\n<p>initializer_list\u672c\u8d28\u5c31\u662f\u4e00\u4e2a\u5927\u62ec\u53f7\u62ec\u8d77\u6765\u7684\u5217\u8868\uff0c\u5982\u679c\u7528auto\u5173\u952e\u5b57\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf\u6765\u63a5\u6536\u4e00\u4e2a\u5927\u62ec\u53f7\u62ec\u8d77\u6765\u7684\u5217\u8868\uff0c\u7136\u540e\u4ee5<code>typeid(\u53d8\u91cf\u540d).name()<\/code>\u7684\u65b9\u5f0f\u67e5\u770b\u8be5\u53d8\u91cf\u7684\u7c7b\u578b\uff0c\u6b64\u65f6\u4f1a\u53d1\u73b0\u8be5\u53d8\u91cf\u7684\u7c7b\u578b\u5c31\u662finitializer_list\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int main()\n{\n    auto il = { 1, 2, 3, 4, 5 };\n    cout &lt;&lt; typeid(il).name() &lt;&lt; endl; \/\/class std::initializer_list&lt;int&gt;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>initializer_list\u7684\u4f7f\u7528\u573a\u666f<\/p>\n<\/blockquote>\n\n\n\n<p>initializer_list\u5bb9\u5668\u6ca1\u6709\u63d0\u4f9b\u5bf9\u5e94\u7684\u589e\u5220\u67e5\u6539\u7b49\u63a5\u53e3\uff0c\u56e0\u4e3ainitializer_list\u5e76\u4e0d\u662f\u4e13\u95e8\u7528\u4e8e\u5b58\u50a8\u6570\u636e\u7684\uff0c\u800c\u662f\u4e3a\u4e86\u8ba9\u5176\u4ed6\u5bb9\u5668\u652f\u6301\u5217\u8868\u521d\u59cb\u5316\u7684\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Date\n{\npublic:\n    Date(int year, int month, int day)\n        :_year(year)\n        , _month(month)\n        , _day(day)\n    {\n        cout &lt;&lt; \"Date(int year, int month, int day)\" &lt;&lt; endl;\n    }\nprivate:\n    int _year;\n    int _month;\n    int _day;\n};\nint main()\n{\n    \/\/\u7528\u5927\u62ec\u53f7\u62ec\u8d77\u6765\u7684\u5217\u8868\u5bf9\u5bb9\u5668\u8fdb\u884c\u521d\u59cb\u5316\n    vector&lt;int&gt; v = { 1, 2, 3, 4, 5 };\n    list&lt;int&gt; l = { 10, 20, 30, 40, 50 };\n    vector&lt;Date&gt; vd = { Date(2022, 8, 29), Date{ 2022, 8, 30 }, { 2022, 8, 31 } };\n    map&lt;string, string&gt; m{ make_pair(\"sort\", \"\u6392\u5e8f\"), { \"insert\", \"\u63d2\u5165\" } };\n\n    \/\/\u7528\u5927\u62ec\u53f7\u62ec\u8d77\u6765\u7684\u5217\u8868\u5bf9\u5bb9\u5668\u8d4b\u503c\n    v = { 5, 4, 3, 2, 1 };\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>C++98\u5e76\u4e0d\u652f\u6301\u76f4\u63a5\u7528\u5217\u8868\u5bf9\u5bb9\u5668\u8fdb\u884c\u521d\u59cb\u5316\uff0c\u8fd9\u79cd\u521d\u59cb\u5316\u65b9\u5f0f\u662f\u5728C++11\u5f15\u5165initializer_list\u540e\u624d\u652f\u6301\u7684\u3002<\/p>\n\n\n\n<p>\u800c\u8fd9\u4e9b\u5bb9\u5668\u4e4b\u6240\u4ee5\u652f\u6301\u4f7f\u7528\u5217\u8868\u8fdb\u884c\u521d\u59cb\u5316\uff0c\u6839\u672c\u539f\u56e0\u662f\u56e0\u4e3aC++11\u7ed9\u8fd9\u4e9b\u5bb9\u5668\u90fd\u589e\u52a0\u4e86\u4e00\u4e2a\u6784\u9020\u51fd\u6570\uff0c\u8fd9\u4e2a\u6784\u9020\u51fd\u6570\u5c31\u662f\u4ee5initializer_list\u4f5c\u4e3a\u53c2\u6570\u7684\u3002<img decoding=\"async\" src=\"https:\/\/cdn.codergodv.xyz\/1814fa336264dedfee26bc6a4cf5c360.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><\/p>\n\n\n\n<p>\u5f53\u7528\u5217\u8868\u5bf9\u5bb9\u5668\u8fdb\u884c\u521d\u59cb\u5316\u65f6\uff0c\u8fd9\u4e2a\u5217\u8868\u88ab\u8bc6\u522b\u6210initializer_list\u7c7b\u578b\uff0c\u4e8e\u662f\u5c31\u4f1a\u8c03\u7528\u8fd9\u4e2a\u65b0\u589e\u7684\u6784\u9020\u51fd\u6570\u5bf9\u8be5\u5bb9\u5668\u8fdb\u884c\u521d\u59cb\u5316\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u65b0\u589e\u7684\u6784\u9020\u51fd\u6570\u8981\u505a\u7684\u5c31\u662f\u904d\u5386initializer_list\u4e2d\u7684\u5143\u7d20\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u5143\u7d20\u4f9d\u6b21\u63d2\u5165\u5230\u8981\u521d\u59cb\u5316\u7684\u5bb9\u5668\u5f53\u4e2d\u5373\u53ef\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>initializer_list\u4f7f\u7528\u793a\u4f8b<\/p>\n<\/blockquote>\n\n\n\n<p>\u4ee5\u535a\u4e3b\u4e4b\u524d<a href=\"https:\/\/blog.csdn.net\/chenlong_cxy\/article\/details\/119254954\">\u6a21\u62df\u5b9e\u73b0\u7684vector\u5bb9\u5668<\/a>\u4e3a\u4f8b\uff0c\u5982\u679c\u8981\u8ba9\u5176\u652f\u6301\u5217\u8868\u521d\u59cb\u5316\uff0c\u5c31\u9700\u8981\u589e\u52a0\u4e00\u4e2a\u4ee5initializer_list\u4f5c\u4e3a\u53c2\u6570\u7684\u6784\u9020\u51fd\u6570\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>namespace cl\n{\n    template&lt;class T&gt;\n    class vector\n    {\n    public:\n        typedef T* iterator;\n        vector(initializer_list&lt;T&gt; il)\n        {\n            _start = new T&#91;il.size()];\n            _finish = _start;\n            _endofstorage = _start + il.size();\n            \/\/\u8fed\u4ee3\u5668\u904d\u5386\n            \/\/typename initializer_list&lt;T&gt;::iterator it = il.begin();\n            \/\/while (it != il.end())\n            \/\/{\n            \/\/  push_back(*it);\n            \/\/  it++;\n            \/\/}\n            \/\/\u8303\u56f4for\u904d\u5386\n            for (auto e : il)\n            {\n                push_back(e);\n            }\n        }\n        vector&lt;T&gt;&amp; operator=(initializer_list&lt;T&gt; il)\n        {\n            vector&lt;T&gt; tmp(il);\n            std::swap(_start, tmp._start);\n            std::swap(_finish, tmp._finish);\n            std::swap(_endofstorage, tmp._endofstorage);\n            return *this;\n        }\n    private:\n        iterator _start;\n        iterator _finish;\n        iterator _endofstorage;\n    };\n}<\/code><\/pre>\n\n\n\n<p><strong>\u8bf4\u660e\u4e00\u4e0b\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u6784\u9020\u51fd\u6570\u4e2d\u904d\u5386initializer_list\u65f6\u53ef\u4ee5\u4f7f\u7528\u8fed\u4ee3\u5668\u904d\u5386\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u8303\u56f4for\u904d\u5386\uff0c\u56e0\u4e3a\u8303\u56f4for\u5e95\u5c42\u5b9e\u9645\u91c7\u7528\u7684\u5c31\u662f\u8fed\u4ee3\u5668\u65b9\u5f0f\u904d\u5386\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528\u8fed\u4ee3\u5668\u65b9\u5f0f\u904d\u5386\u65f6\uff0c\u9700\u8981\u5728\u8fed\u4ee3\u5668\u7c7b\u578b\u524d\u9762\u52a0\u4e0atypename\u5173\u952e\u5b57\uff0c\u6307\u660e\u8fd9\u662f\u4e00\u4e2a\u7c7b\u578b\u540d\u5b57\u3002\u56e0\u4e3a\u8fd9\u4e2a\u8fed\u4ee3\u5668\u7c7b\u578b\u5b9a\u4e49\u5728\u4e00\u4e2a\u7c7b\u6a21\u677f\u4e2d\uff0c\u5728\u8be5\u7c7b\u6a21\u677f\u672a\u88ab\u5b9e\u4f8b\u5316\u4e4b\u524d\u7f16\u8bd1\u5668\u662f\u65e0\u6cd5\u8bc6\u522b\u8fd9\u4e2a\u7c7b\u578b\u7684\u3002<\/li>\n\n\n\n<li>\u6700\u597d\u4e5f\u589e\u52a0\u4e00\u4e2a\u4ee5initializer_list\u4f5c\u4e3a\u53c2\u6570\u7684\u8d4b\u503c\u8fd0\u7b97\u7b26\u91cd\u8f7d\u51fd\u6570\uff0c\u4ee5\u652f\u6301\u76f4\u63a5\u7528\u5217\u8868\u5bf9\u5bb9\u5668\u5bf9\u8c61\u8fdb\u884c\u8d4b\u503c\uff0c\u4f46\u5b9e\u9645\u4e5f\u53ef\u4ee5\u4e0d\u589e\u52a0\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u5982\u679c\u6ca1\u6709\u589e\u52a0\u4ee5initializer_list\u4f5c\u4e3a\u53c2\u6570\u7684\u8d4b\u503c\u8fd0\u7b97\u7b26\u91cd\u8f7d\u51fd\u6570\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u4e5f\u53ef\u4ee5\u6b63\u5e38\u6267\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vector&lt;int&gt; v = { 1, 2, 3, 4, 5 };\nv = { 5, 4, 3, 2, 1 };<\/code><\/pre>\n\n\n\n<p>\u89e3\u91ca\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5bf9\u4e8e\u7b2c\u4e00\u884c\u4ee3\u7801\uff0c\u5c31\u662f\u8c03\u7528\u4ee5initializer_list\u4f5c\u4e3a\u53c2\u6570\u7684\u6784\u9020\u51fd\u6570\u5b8c\u6210\u5bf9\u8c61\u7684\u521d\u59cb\u5316\u3002<\/li>\n\n\n\n<li>\u800c\u5bf9\u4e8e\u7b2c\u4e8c\u884c\u4ee3\u7801\uff0c\u4f1a\u5148\u8c03\u7528initializer_list\u4f5c\u4e3a\u53c2\u6570\u7684\u6784\u9020\u51fd\u6570\u6784\u9020\u51fa\u4e00\u4e2avector\u5bf9\u8c61\uff0c\u7136\u540e\u518d\u8c03\u7528vector\u539f\u6709\u7684\u8d4b\u503c\u8fd0\u7b97\u7b26\u91cd\u8f7d\u51fd\u6570\u5b8c\u6210\u4e24\u4e2avector\u5bf9\u8c61\u4e4b\u95f4\u7684\u8d4b\u503c\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u58f0\u660e<\/h2>\n\n\n\n<p>C++11\u63d0\u4f9b\u4e86\u591a\u79cd\u7b80\u5316\u58f0\u660e\u7684\u65b9\u5f0f\uff0c\u5c24\u5176\u662f\u5728\u4f7f\u7528\u6a21\u677f\u7684\u65f6\u5019\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>auto<\/p>\n<\/blockquote>\n\n\n\n<p>\u5728C++98\u4e2dauto\u662f\u4e00\u4e2a\u5b58\u50a8\u7c7b\u578b\u7684\u8bf4\u660e\u7b26\uff0c\u8868\u660e\u53d8\u91cf\u662f\u5c40\u90e8\u81ea\u52a8\u5b58\u50a8\u7c7b\u578b\uff0c\u4f46\u662f\u5c40\u90e8\u57df\u4e2d\u5b9a\u4e49\u5c40\u90e8\u7684\u53d8\u91cf\u9ed8\u8ba4\u5c31\u662f\u81ea\u52a8\u5b58\u50a8\u7c7b\u578b\uff0c\u6240\u4ee5auto\u5c31\u6ca1\u4ec0\u4e48\u4ef7\u503c\u4e86\u3002<\/p>\n\n\n\n<p>C++11\u4e2d\u5e9f\u5f03auto\u539f\u6765\u7684\u7528\u6cd5\uff0c\u5c06\u5176\u7528\u4e8e\u5b9e\u73b0\u81ea\u52a8\u7c7b\u578b\u63a8\u65ad\u3002\u8fd9\u6837\u8981\u6c42\u5fc5\u987b\u8fdb\u884c\u663e\u793a\u521d\u59cb\u5316\uff0c\u8ba9\u7f16\u8bd1\u5668\u5c06\u5b9a\u4e49\u5bf9\u8c61\u7684\u7c7b\u578b\u8bbe\u7f6e\u4e3a\u521d\u59cb\u5316\u503c\u7684\u7c7b\u578b\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int main()\n{\n    int i = 10;\n    auto p = &amp;i;\n    auto pf = strcpy;\n\n    cout &lt;&lt; typeid(p).name() &lt;&lt; endl;  \/\/int *\n    cout &lt;&lt; typeid(pf).name() &lt;&lt; endl; \/\/char * (__cdecl*)(char *,char const *)\n\n    map&lt;string, string&gt; dict = { { \"sort\", \"\u6392\u5e8f\" }, { \"insert\", \"\u63d2\u5165\" } };\n    \/\/map&lt;string, string&gt;::iterator it = dict.begin();\n    auto it = dict.begin();  \/\/\u7b80\u5316\u4ee3\u7801\n\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>\u81ea\u52a8\u7c7b\u578b\u63a8\u65ad\u5728\u67d0\u4e9b\u573a\u666f\u4e0b\u8fd8\u662f\u975e\u5e38\u5fc5\u8981\u7684\uff0c\u56e0\u4e3a\u7f16\u8bd1\u5668\u8981\u6c42\u5728\u5b9a\u4e49\u53d8\u91cf\u65f6\u5fc5\u987b\u5148\u7ed9\u51fa\u53d8\u91cf\u7684\u5b9e\u9645\u7c7b\u578b\uff0c\u800c\u5982\u679c\u6211\u4eec\u81ea\u5df1\u8bbe\u5b9a\u7c7b\u578b\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u53ef\u80fd\u4f1a\u51fa\u95ee\u9898\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int main()\n{\n    short a = 32670;\n    short b = 32670;\n    \/\/c\u5982\u679c\u7ed9\u6210short\uff0c\u4f1a\u9020\u6210\u6570\u636e\u4e22\u5931\uff0c\u5982\u679c\u80fd\u591f\u8ba9\u7f16\u8bd1\u5668\u6839\u636ea+b\u7684\u7ed3\u679c\u63a8\u5bfcc\u7684\u5b9e\u9645\u7c7b\u578b\uff0c\u5c31\u4e0d\u4f1a\u5b58\u5728\u95ee\u9898\n    short c = a + b;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>decltype<\/p>\n<\/blockquote>\n\n\n\n<p>\u5173\u952e\u5b57decltype\u53ef\u4ee5\u5c06\u53d8\u91cf\u7684\u7c7b\u578b\u58f0\u660e\u4e3a\u8868\u8fbe\u5f0f\u6307\u5b9a\u7684\u7c7b\u578b\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>template&lt;class T1, class T2&gt;\nvoid F(T1 t1, T2 t2)\n{\n    decltype(t1*t2) ret;\n    cout &lt;&lt; typeid(ret).name() &lt;&lt; endl;\n}\nint main()\n{\n    const int x = 1;\n    double y = 2.2;\n\n    decltype(x*y) ret;\n    decltype(&amp;x) p;\n    cout &lt;&lt; typeid(ret).name() &lt;&lt; endl; \/\/double\n    cout &lt;&lt; typeid(p).name() &lt;&lt; endl;   \/\/int const *\n\n    F(1, 'a'); \/\/int\n    F(1, 2.2); \/\/double\n\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>\u6ce8\u610f\uff1a<\/strong> \u901a\u8fc7<code>typeid(\u53d8\u91cf\u540d).name()<\/code>\u7684\u65b9\u5f0f\u53ef\u4ee5\u83b7\u53d6\u4e00\u4e2a\u53d8\u91cf\u7684\u7c7b\u578b\uff0c\u4f46\u65e0\u6cd5\u7528\u83b7\u53d6\u5230\u7684\u8fd9\u4e2a\u7c7b\u578b\u53bb\u5b9a\u4e49\u53d8\u91cf\u3002<\/p>\n\n\n\n<p>decltype\u9664\u4e86\u80fd\u591f\u63a8\u6f14\u8868\u8fbe\u5f0f\u7684\u7c7b\u578b\uff0c\u8fd8\u80fd\u63a8\u6f14\u51fd\u6570\u8fd4\u56de\u503c\u7684\u7c7b\u578b\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void* GetMemory(size_t size)\n{\n    return malloc(size);\n}\nint main()\n{\n    \/\/\u5982\u679c\u6ca1\u6709\u5e26\u53c2\u6570\uff0c\u63a8\u5bfc\u51fd\u6570\u7684\u7c7b\u578b\n    cout &lt;&lt; typeid(decltype(GetMemory)).name() &lt;&lt; endl;\n    \/\/\u5982\u679c\u5e26\u53c2\u6570\u5217\u8868\uff0c\u63a8\u5bfc\u7684\u662f\u51fd\u6570\u8fd4\u56de\u503c\u7684\u7c7b\u578b\uff0c\u6ce8\u610f\uff1a\u6b64\u5904\u53ea\u662f\u63a8\u6f14\uff0c\u4e0d\u4f1a\u6267\u884c\u51fd\u6570\n    cout &lt;&lt; typeid(decltype(GetMemory(0))).name() &lt;&lt; endl;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>decltype\u4e0d\u4ec5\u53ef\u4ee5\u6307\u5b9a\u5b9a\u4e49\u51fa\u7684\u53d8\u91cf\u7c7b\u578b\uff0c\u8fd8\u53ef\u4ee5\u6307\u5b9a\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>template&lt;class T1, class T2&gt;\nauto Add(T1 t1, T2 t2)-&gt;decltype(t1+t2)\n{\n    decltype(t1+t2) ret;\n    ret = t1 + t2;\n    cout &lt;&lt; typeid(ret).name() &lt;&lt; endl;\n    return ret;\n}\nint main()\n{\n    cout &lt;&lt; Add(1, 2) &lt;&lt; endl;;   \/\/int\n    cout &lt;&lt; Add(1, 2.2) &lt;&lt; endl;; \/\/double\n    return 0;\n}<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>nullptr<\/p>\n<\/blockquote>\n\n\n\n<p>\u7531\u4e8eC++\u4e2dNULL\u88ab\u5b9a\u4e49\u6210\u5b57\u9762\u91cf0\uff0c\u8fd9\u6837\u5c31\u53ef\u80fd\u4f1a\u5e26\u6765\u4e00\u4e9b\u95ee\u9898\uff0c\u56e0\u4e3a0\u65e2\u80fd\u8868\u793a\u6307\u9488\u5e38\u91cf\uff0c\u53c8\u80fd\u8868\u793a\u6574\u578b\u5e38\u91cf\u3002\u6240\u4ee5\u51fa\u4e8e\u6e05\u6670\u548c\u5b89\u5168\u7684\u89d2\u5ea6\u8003\u8651\uff0cC++11\u4e2d\u65b0\u589e\u4e86nullptr\uff0c\u7528\u4e8e\u8868\u793a\u7a7a\u6307\u9488\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* Define NULL pointer value *\/\n#ifndef NULL\n#ifdef __cplusplus\n#define NULL    0\n#else  \/* __cplusplus *\/\n#define NULL    ((void *)0)\n#endif  \/* __cplusplus *\/\n#endif  \/* NULL *\/<\/code><\/pre>\n\n\n\n<p>\u5728\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\u4f7f\u7528NULL\u4e0d\u4f1a\u5b58\u5728\u4ec0\u4e48\u95ee\u9898\uff0c\u4f46\u662f\u5728\u67d0\u4e9b\u6781\u7aef\u573a\u666f\u4e0b\u5c31\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5339\u914d\u9519\u8bef\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void f(int arg)\n{\n    cout &lt;&lt; \"void f(int arg)\" &lt;&lt; endl;\n}\nvoid f(int* arg)\n{\n    cout &lt;&lt; \"void f(int* arg)\" &lt;&lt; endl;\n}\nint main()\n{\n    f(NULL);    \/\/void f(int arg)\n    f(nullptr); \/\/void f(int* arg)\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>NULL\u548cnullptr\u7684\u542b\u4e49\u90fd\u662f\u7a7a\u6307\u9488\uff0c\u6240\u4ee5\u8fd9\u91cc\u8c03\u7528\u51fd\u6570\u65f6\u80af\u5b9a\u5e0c\u671b\u5339\u914d\u5230\u7684\u90fd\u662f\u53c2\u6570\u7c7b\u578b\u4e3a<code>int*<\/code>\u7684\u91cd\u8f7d\u51fd\u6570\uff0c\u4f46\u6700\u7ec8\u5374\u56e0\u4e3aNULL\u672c\u8d28\u662f\u5b57\u9762\u91cf0\uff0c\u800c\u5bfc\u81f4NULL\u5339\u914d\u5230\u4e86\u53c2\u6570\u4e3a<code>int<\/code>\u7c7b\u578b\u7684\u91cd\u8f7d\u51fd\u6570\uff0c\u56e0\u6b64\u5728C++\u4e2d\u4e00\u822c\u63a8\u8350\u4f7f\u7528nullptr\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u8303\u56f4for\u5faa\u73af<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u8303\u56f4for\u7684\u8bed\u6cd5<\/p>\n<\/blockquote>\n\n\n\n<p>\u82e5\u662f\u5728C++98\u4e2d\u6211\u4eec\u8981\u904d\u5386\u4e00\u4e2a\u6570\u7ec4\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int main()\n{\n    int arr&#91;] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };\n    \/\/\u5c06\u6570\u7ec4\u5143\u7d20\u503c\u5168\u90e8\u4e58\u4ee52\n    for (int i = 0; i &lt; sizeof(arr) \/ sizeof(arr&#91;0]); i++)\n    {\n        arr&#91;i] *= 2;\n    }\n    \/\/\u6253\u5370\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\n    for (int i = 0; i &lt; sizeof(arr) \/ sizeof(arr&#91;0]); i++)\n    {\n        cout &lt;&lt; arr&#91;i] &lt;&lt; \" \";\n    }\n    cout &lt;&lt; endl;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>\u4ee5\u4e0a\u65b9\u5f0f\u4e5f\u662fC\u8bed\u8a00\u4e2d\u6240\u7528\u7684\u904d\u5386\u6570\u7ec4\u7684\u65b9\u5f0f\uff0c\u4f46\u5bf9\u4e8e\u4e00\u4e2a\u6709\u8303\u56f4\u7684\u96c6\u5408\u800c\u8a00\uff0c\u5faa\u73af\u662f\u591a\u4f59\u7684\uff0c\u6709\u65f6\u8fd8\u5bb9\u6613\u72af\u9519\u3002<\/p>\n\n\n\n<p>C++11\u4e2d\u5f15\u5165\u4e86\u57fa\u4e8e\u8303\u56f4\u7684for\u5faa\u73af\uff0cfor\u5faa\u73af\u540e\u7684\u62ec\u53f7\u7531\u5192\u53f7\u5206\u4e3a\u4e24\u90e8\u5206\uff0c\u7b2c\u4e00\u90e8\u5206\u662f\u8303\u56f4\u5185\u7528\u4e8e\u8fed\u4ee3\u7684\u53d8\u91cf\uff0c\u7b2c\u4e8c\u90e8\u5206\u5219\u8868\u793a\u88ab\u8fed\u4ee3\u7684\u8303\u56f4\u3002\u6bd4\u5982<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int main()\n{\n    int arr&#91;] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };\n    \/\/\u5c06\u6570\u7ec4\u5143\u7d20\u503c\u5168\u90e8\u4e58\u4ee52\n    for (auto&amp; e : arr)\n    {\n        e *= 2;\n    }\n    \/\/\u6253\u5370\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\n    for (auto e : arr)\n    {\n        cout &lt;&lt; e &lt;&lt; \" \";\n    }\n    cout &lt;&lt; endl;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>\u6ce8\u610f\uff1a<\/strong> \u4e0e\u666e\u901a\u5faa\u73af\u7c7b\u4f3c\uff0c\u53ef\u7528continue\u6765\u7ed3\u675f\u672c\u6b21\u5faa\u73af\uff0c\u4e5f\u53ef\u4ee5\u7528break\u6765\u8df3\u51fa\u6574\u4e2a\u5faa\u73af\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u8303\u56f4for\u7684\u4f7f\u7528\u6761\u4ef6<\/p>\n<\/blockquote>\n\n\n\n<p><strong>\u4e00\u3001for\u5faa\u73af\u8fed\u4ee3\u7684\u8303\u56f4\u5fc5\u987b\u662f\u786e\u5b9a\u7684<\/strong><br>\u2003\u2003\u5bf9\u4e8e\u6570\u7ec4\u800c\u8a00\uff0c\u5c31\u662f\u6570\u7ec4\u4e2d\u7b2c\u4e00\u4e2a\u5143\u7d20\u548c\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u8303\u56f4\uff1b\u5bf9\u4e8e\u7c7b\u800c\u8a00\uff0c\u5e94\u8be5\u63d0\u4f9bbegin\u548cend\u7684\u65b9\u6cd5\uff0cbegin\u548cend\u5c31\u662ffor\u5faa\u73af\u8fed\u4ee3\u7684\u8303\u56f4\u3002<\/p>\n\n\n\n<p><strong>\u4e8c\u3001\u8fed\u4ee3\u7684\u5bf9\u8c61\u8981\u652f\u6301++\u548c==\u64cd\u4f5c<\/strong><br>\u2003\u2003\u8303\u56f4for\u672c\u8d28\u4e0a\u662f\u7531\u8fed\u4ee3\u5668\u652f\u6301\u7684\uff0c\u5728\u4ee3\u7801\u7f16\u8bd1\u7684\u65f6\u5019\uff0c\u7f16\u8bd1\u5668\u4f1a\u81ea\u52a8\u5c06\u8303\u56f4for\u66ff\u6362\u4e3a\u8fed\u4ee3\u5668\u7684\u5f62\u5f0f\u3002\u800c\u7531\u4e8e\u5728\u4f7f\u7528\u8fed\u4ee3\u5668\u904d\u5386\u65f6\u9700\u8981\u5bf9\u5bf9\u8c61\u8fdb\u884c++\u548c==\u64cd\u4f5c\uff0c\u56e0\u6b64\u4f7f\u7528\u8303\u56f4for\u7684\u5bf9\u8c61\u4e5f\u9700\u8981\u652f\u6301++\u548c==\u64cd\u4f5c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/so.csdn.net\/so\/search?q=STL&amp;spm=1001.2101.3001.7020\">STL<\/a>\u4e2d\u4e00\u4e9b\u53d8\u5316<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u65b0\u5bb9\u5668<\/p>\n<\/blockquote>\n\n\n\n<p>C++11\u4e2d\u65b0\u589e\u4e86\u56db\u4e2a\u5bb9\u5668\uff0c\u5206\u522b\u662farray\u3001forward_list\u3001unordered_map\u548cunordered_set\u3002<\/p>\n\n\n\n<p><strong>\u4e00\u3001array\u5bb9\u5668<\/strong><br>array\u5bb9\u5668\u672c\u8d28\u5c31\u662f\u4e00\u4e2a\u9759\u6001\u6570\u7ec4\uff0c\u5373\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\u7ec4\u3002<\/p>\n\n\n\n<p>array\u5bb9\u5668\u6709\u4e24\u4e2a\u6a21\u677f\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u6a21\u677f\u53c2\u6570\u4ee3\u8868\u7684\u662f\u5b58\u50a8\u7684\u7c7b\u578b\uff0c\u7b2c\u4e8c\u4e2a\u6a21\u677f\u53c2\u6570\u662f\u4e00\u4e2a\u975e\u7c7b\u578b\u6a21\u677f\u53c2\u6570\uff0c\u4ee3\u8868\u7684\u662f\u6570\u7ec4\u4e2d\u53ef\u5b58\u50a8\u5143\u7d20\u7684\u4e2a\u6570\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int main()\n{\n    array&lt;int, 10&gt; a1;   \/\/\u5b9a\u4e49\u4e00\u4e2a\u53ef\u5b58\u50a810\u4e2aint\u7c7b\u578b\u5143\u7d20\u7684array\u5bb9\u5668\n    array&lt;double, 5&gt; a2; \/\/\u5b9a\u4e49\u4e00\u4e2a\u53ef\u5b58\u50a85\u4e2adouble\u7c7b\u578b\u5143\u7d20\u7684array\u5bb9\u5668\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>array\u5bb9\u5668\u4e0e\u666e\u901a\u6570\u7ec4\u5bf9\u6bd4\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>array\u5bb9\u5668\u4e0e\u666e\u901a\u6570\u7ec4\u4e00\u6837\uff0c\u652f\u6301\u901a\u8fc7<code>[]<\/code>\u8bbf\u95ee\u6307\u5b9a\u4e0b\u6807\u7684\u5143\u7d20\uff0c\u4e5f\u652f\u6301\u4f7f\u7528\u8303\u56f4for\u904d\u5386\u6570\u7ec4\u5143\u7d20\uff0c\u5e76\u4e14\u521b\u5efa\u540e\u6570\u7ec4\u7684\u5927\u5c0f\u4e5f\u4e0d\u53ef\u6539\u53d8\u3002<\/li>\n\n\n\n<li>array\u5bb9\u5668\u4e0e\u666e\u901a\u6570\u7ec4\u4e0d\u540c\u4e4b\u5904\u5c31\u662f\uff0carray\u5bb9\u5668\u7528\u4e00\u4e2a\u7c7b\u5bf9\u6570\u7ec4\u8fdb\u884c\u4e86\u5c01\u88c5\uff0c\u5e76\u4e14\u5728\u8bbf\u95eearray\u5bb9\u5668\u4e2d\u7684\u5143\u7d20\u65f6\u4f1a\u8fdb\u884c\u8d8a\u754c\u68c0\u67e5\u3002\u7528<code>[]<\/code>\u8bbf\u95ee\u5143\u7d20\u65f6\u91c7\u7528\u65ad\u8a00\u68c0\u67e5\uff0c\u8c03\u7528<code>at<\/code>\u6210\u5458\u51fd\u6570\u8bbf\u95ee\u5143\u7d20\u65f6\u91c7\u7528\u629b\u5f02\u5e38\u68c0\u67e5\u3002<\/li>\n\n\n\n<li>\u800c\u5bf9\u4e8e\u666e\u901a\u6570\u7ec4\u6765\u8bf4\uff0c\u4e00\u822c\u53ea\u6709\u5bf9\u6570\u7ec4\u8fdb\u884c\u5199\u64cd\u4f5c\u65f6\u624d\u4f1a\u68c0\u67e5\u8d8a\u754c\uff0c\u5982\u679c\u53ea\u662f\u8d8a\u754c\u8fdb\u884c\u8bfb\u64cd\u4f5c\u53ef\u80fd\u5e76\u4e0d\u4f1a\u62a5\u9519\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u4f46array\u5bb9\u5668\u4e0e\u5176\u4ed6\u5bb9\u5668\u4e0d\u540c\u7684\u662f\uff0carray\u5bb9\u5668\u7684\u5bf9\u8c61\u662f\u521b\u5efa\u5728\u6808\u4e0a\u7684\uff0c\u56e0\u6b64array\u5bb9\u5668\u4e0d\u9002\u5408\u5b9a\u4e49\u592a\u5927\u7684\u6570\u7ec4\u3002<\/p>\n\n\n\n<p><strong>\u4e8c\u3001forward_list\u5bb9\u5668<\/strong><br>forward_list\u5bb9\u5668\u672c\u8d28\u5c31\u662f\u4e00\u4e2a\u5355\u94fe\u8868\u3002<\/p>\n\n\n\n<p>forward_list\u5f88\u5c11\u4f7f\u7528\uff0c\u539f\u56e0\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>forward_list\u53ea\u652f\u6301\u5934\u63d2\u5934\u5220\uff0c\u4e0d\u652f\u6301\u5c3e\u63d2\u5c3e\u5220\uff0c\u56e0\u4e3a\u5355\u94fe\u8868\u5728\u8fdb\u884c\u5c3e\u63d2\u5c3e\u5220\u65f6\u9700\u8981\u5148\u627e\u5c3e\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(N)\u3002<\/li>\n\n\n\n<li>forward_list\u63d0\u4f9b\u7684\u63d2\u5165\u51fd\u6570\u53eb\u505ainsert_after\uff0c\u4e5f\u5c31\u662f\u5728\u6307\u5b9a\u5143\u7d20\u7684\u540e\u9762\u63d2\u5165\u4e00\u4e2a\u5143\u7d20\uff0c\u800c\u4e0d\u50cf\u5176\u4ed6\u5bb9\u5668\u662f\u5728\u6307\u5b9a\u5143\u7d20\u7684\u524d\u9762\u63d2\u5165\u4e00\u4e2a\u5143\u7d20\uff0c\u56e0\u4e3a\u5355\u94fe\u8868\u5982\u679c\u8981\u5728\u6307\u5b9a\u5143\u7d20\u7684\u524d\u9762\u63d2\u5165\u5143\u7d20\uff0c\u8fd8\u8981\u904d\u5386\u94fe\u8868\u627e\u5230\u8be5\u5143\u7d20\u7684\u524d\u4e00\u4e2a\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(N)\u3002<\/li>\n\n\n\n<li>forward_list\u63d0\u4f9b\u7684\u5220\u9664\u51fd\u6570\u53eb\u505aerase_after\uff0c\u4e5f\u5c31\u662f\u5220\u9664\u6307\u5b9a\u5143\u7d20\u540e\u9762\u7684\u4e00\u4e2a\u5143\u7d20\uff0c\u56e0\u4e3a\u5355\u94fe\u8868\u5982\u679c\u8981\u5220\u9664\u6307\u5b9a\u5143\u7d20\uff0c\u8fd8\u9700\u8981\u8fd8\u8981\u904d\u5386\u94fe\u8868\u627e\u5230\u6307\u5b9a\u5143\u7d20\u7684\u524d\u4e00\u4e2a\u5143\u7d20\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(N)\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u56e0\u6b64\u4e00\u822c\u60c5\u51b5\u4e0b\u8981\u7528\u94fe\u8868\u6211\u4eec\u8fd8\u662f\u9009\u62e9\u4f7f\u7528list\u5bb9\u5668\u3002<\/p>\n\n\n\n<p><strong>\u4e09\u3001unordered_map\u548cunordered_set\u5bb9\u5668<\/strong><br>unordered_map\u548cunordered_set\u5bb9\u5668\u5e95\u5c42\u91c7\u7528\u7684\u90fd\u662f\u54c8\u5e0c\u8868\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e24\u4e2a\u5bb9\u5668\u662f\u975e\u5e38\u6709\u7528\u7684\uff0c\u535a\u4e3b\u5176\u4ed6\u535a\u5ba2\u5bf9\u8fd9\u4e24\u4e2a\u5bb9\u5668\u8fdb\u884c\u4e86\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/blog.csdn.net\/chenlong_cxy\/article\/details\/122277348\">unordered_set\u3001unordered_map\u7684\u4ecb\u7ecd\u53ca\u4f7f\u7528<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/blog.csdn.net\/chenlong_cxy\/article\/details\/122508621\">unordered_map\u548cunordered_set\u7684\u6a21\u62df\u5b9e\u73b0<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/blog.csdn.net\/chenlong_cxy\/article\/details\/122262852\">map\/set\u548cunordered_map\/unordered_set\u7684\u533a\u522b\u53ca\u5176\u9002\u7528\u60c5\u51b5<\/a><\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5b57\u7b26\u4e32\u8f6c\u6362\u51fd\u6570<\/p>\n<\/blockquote>\n\n\n\n<p>C++11\u63d0\u4f9b\u4e86\u5404\u79cd\u5185\u7f6e\u7c7b\u578b\u4e0estring\u4e4b\u95f4\u76f8\u4e92\u8f6c\u6362\u7684\u51fd\u6570\uff0c\u6bd4\u5982to_string\u3001stoi\u3001stol\u3001stod\u7b49\u51fd\u6570\u3002<\/p>\n\n\n\n<p><strong>\u4e00\u3001\u5185\u7f6e\u7c7b\u578b\u8f6c\u6362\u4e3astring<\/strong><br>\u5c06\u5185\u7f6e\u7c7b\u578b\u8f6c\u6362\u6210string\u7c7b\u578b\u7edf\u4e00\u8c03\u7528to_string\u51fd\u6570\uff0c\u56e0\u4e3ato_string\u51fd\u6570\u4e3a\u5404\u79cd\u5185\u7f6e\u7c7b\u578b\u91cd\u8f7d\u4e86\u5bf9\u5e94\u7684\u5904\u7406\u51fd\u6570\u3002<img decoding=\"async\" src=\"https:\/\/cdn.codergodv.xyz\/66ae30560fa058174c90f9a085665b01.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><\/p>\n\n\n\n<p><strong>\u4e8c\u3001string\u8f6c\u6362\u6210\u5185\u7f6e\u7c7b\u578b<\/strong><br>\u5982\u679c\u8981\u5c06string\u7c7b\u578b\u8f6c\u6362\u6210\u5185\u7f6e\u7c7b\u578b\uff0c\u5219\u8c03\u7528\u5bf9\u5e94\u7684\u8f6c\u6362\u51fd\u6570\u5373\u53ef\u3002<img decoding=\"async\" src=\"https:\/\/cdn.codergodv.xyz\/802d003a68c065c74cd59a2b01ae3694.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5bb9\u5668\u4e2d\u7684\u4e00\u4e9b\u65b0\u65b9\u6cd5<\/p>\n<\/blockquote>\n\n\n\n<p>C++11\u4e3a\u6bcf\u4e2a\u5bb9\u5668\u90fd\u589e\u52a0\u4e86\u4e00\u4e9b\u65b0\u65b9\u6cd5\uff0c\u6bd4\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u63d0\u4f9b\u4e86\u4e00\u4e2a\u4ee5initializer_list\u4f5c\u4e3a\u53c2\u6570\u7684\u6784\u9020\u51fd\u6570\uff0c\u7528\u4e8e\u652f\u6301\u5217\u8868\u521d\u59cb\u5316\u3002<\/li>\n\n\n\n<li>\u63d0\u4f9b\u4e86cbegin\u548ccend\u65b9\u6cd5\uff0c\u7528\u4e8e\u8fd4\u56deconst\u8fed\u4ee3\u5668\u3002<\/li>\n\n\n\n<li>\u63d0\u4f9b\u4e86emplace\u7cfb\u5217\u65b9\u6cd5\uff0c\u5e76\u5728\u5bb9\u5668\u539f\u6709\u63d2\u5165\u65b9\u6cd5\u7684\u57fa\u7840\u4e0a\u91cd\u8f7d\u4e86\u4e00\u4e2a\u53f3\u503c\u5f15\u7528\u7248\u672c\u7684\u63d2\u5165\u51fd\u6570\uff0c\u7528\u4e8e\u63d0\u9ad8\u5411\u5bb9\u5668\u4e2d\u63d2\u5165\u5143\u7d20\u7684\u6548\u7387\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\u8bf4\u660e\u4e00\u4e0b\uff1aemplace\u7cfb\u5217\u65b9\u6cd5\u548c\u65b0\u589e\u7684\u63d2\u5165\u51fd\u6570\u63d0\u9ad8\u5bb9\u5668\u63d2\u5165\u6548\u7387\u7684\u539f\u7406\uff0c\u6d89\u53caC++11\u4e2d\u7684\u53f3\u503c\u5f15\u7528\u3001\u79fb\u52a8\u8bed\u4e49\u548c\u6a21\u677f\u7684\u53ef\u53d8\u53c2\u6570\u7b49\u673a\u5236\uff0c\u535a\u4e3b\u540e\u7eed\u535a\u5ba2\u4f1a\u9646\u7eed\u66f4\u65b0\u3002<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>C++11\u7b80\u4ecb C++11\u589e\u52a0\u7684\u8bed\u6cd5\u7279\u6027\u975e\u5e38\u591a\uff0c\u672c\u7bc7\u535a\u5ba2\u53ea\u8bb2\u89e3\u4e00\u90e8\u5206\u7b80\u5355\u7684\u8bed\u6cd5\uff0c\u540e\u9762\u8fd8\u4f1a\u9646\u7eed\u66f4\u65b0C++11\u7684\u4e00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,1],"tags":[22],"class_list":["post-90","post","type-post","status-publish","format-standard","hentry","category-cpp","category-learn","tag-c11"],"_links":{"self":[{"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/posts\/90","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=90"}],"version-history":[{"count":1,"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/posts\/90\/revisions"}],"predecessor-version":[{"id":91,"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/posts\/90\/revisions\/91"}],"wp:attachment":[{"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=90"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=90"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=90"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}