{"id":40926,"date":"2025-05-30T12:26:41","date_gmt":"2025-05-30T04:26:41","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/40926.html"},"modified":"2025-05-30T12:26:41","modified_gmt":"2025-05-30T04:26:41","slug":"%e3%80%90c%e6%8c%87%e5%8d%97%e3%80%91stl%e5%ae%b9%e5%99%a8%e7%9a%84%e5%ae%89%e5%85%a8%e9%9d%a9%e5%91%bd%ef%bc%9a%e5%a6%82%e4%bd%95%e5%b0%81%e8%a3%85vector%e6%9d%9c%e7%bb%9d%e8%b6%8a%e7%95%8c","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/40926.html","title":{"rendered":"\u3010C++\u6307\u5357\u3011STL\u5bb9\u5668\u7684\u5b89\u5168\u9769\u547d\uff1a\u5982\u4f55\u5c01\u88c5Vector\u675c\u7edd\u8d8a\u754c\u8bbf\u95ee\u4e0e\u8fed\u4ee3\u5668\u5931\u6548\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042638-6839337ee0fef.jpg\" \/><\/p>\n<p>&#x1f31f;\u00a0<span style=\"color:#38d8f0\">\u5404\u4f4d\u770b\u5b98\u597d<\/span>&#xff0c;\u6211\u662fegoist2023&#xff01;<\/p>\n<p>&#x1f30d;\u00a0\u79cd\u4e00\u68f5\u6811\u6700\u597d\u662f\u5341\u5e74\u524d&#xff0c;\u5176\u6b21\u662f\u73b0\u5728&#xff01;<\/p>\n<p><span style=\"color:#4da8ee\">&#x1f680;\u00a0\u4f7f\u7528STL\u7684\u4e09\u4e2a\u5883\u754c&#xff1a;\u80fd\u7528&#xff0c;\u660e\u7406&#xff0c;\u80fd\u6269\u5c55<\/span><\/p>\n<p><span style=\"color:#4da8ee\">&#x1f44d;\u00a0\u5982\u679c\u89c9\u5f97\u8fd9\u7bc7\u6587\u7ae0\u6709\u5e2e\u52a9&#xff0c;\u6b22\u8fce\u60a8\u4e00\u952e\u4e09\u8fde&#xff0c;\u5206\u4eab\u7ed9\u66f4\u591a\u4eba\u54e6&#xff01;<\/span><\/p>\n<h2>\u4e86\u89e3vector\u5e38\u7528\u63a5\u53e3<\/h2>\n<p>vector\u662fC&#043;&#043;\u6807\u51c6\u6a21\u677f\u5e93\u4e2d\u7684\u90e8\u5206\u5185\u5bb9&#xff0c;\u4e2d\u6587\u5076\u5c14\u8bd1\u4f5c\u201c\u5bb9\u5668\u201d&#xff0c;\u4f46\u5e76\u4e0d\u51c6\u786e\u3002\u5b83\u662f\u4e00\u4e2a\u591a\u529f\u80fd\u7684&#xff0c;\u80fd\u591f<span style=\"color:#956fe7\">\u64cd\u4f5c\u591a\u79cd\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u7684\u6a21\u677f\u7c7b\u548c\u51fd\u6570\u5e93<\/span>\u3002vector\u4e4b\u6240\u4ee5\u88ab\u8ba4\u4e3a\u662f\u4e00\u4e2a\u5bb9\u5668&#xff0c;\u662f\u56e0\u4e3a\u5b83<span style=\"color:#956fe7\">\u80fd\u591f\u50cf\u5bb9\u5668\u4e00\u6837\u5b58\u653e\u5404\u79cd\u7c7b\u578b\u7684\u5bf9\u8c61<\/span>&#xff0c;\u7b80\u5355\u5730\u8bf4&#xff0c;<span style=\"color:#fe2c24\">vector\u662f\u4e00\u4e2a\u80fd\u591f\u5b58\u653e\u4efb\u610f\u7c7b\u578b\u7684\u52a8\u6001\u6570\u7ec4<\/span>&#xff0c;\u80fd\u591f\u589e\u52a0\u548c\u538b\u7f29\u6570\u636e\u3002<\/p>\n<h3>\u5e38\u89c1\u6784\u9020<\/h3>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:600px\">\n<tbody>\n<tr>\n<td style=\"width:401px\">\n<p>     <span style=\"color:#4183c4\">(constructor)<\/span><br \/>\n     <span style=\"color:#777777\">\u6784\u9020\u51fd\u6570\u58f0\u660e<\/span>\n     <\/td>\n<td style=\"width:197px\"><span style=\"color:#777777\">\u63a5\u53e3\u8bf4\u660e<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width:401px\">\n<p>     <span style=\"color:#777777\">vector()<\/span><br \/>\n     <span style=\"color:#777777\">&#xff08;\u91cd\u70b9&#xff09;<\/span>\n     <\/td>\n<td style=\"width:197px\"><span style=\"color:#777777\">\u65e0\u53c2\u6784\u9020<\/span><\/td>\n<\/tr>\n<tr>\n<td style=\"width:401px\">\n<p>     <span style=\"color:#777777\">vector<\/span><br \/>\n     <span style=\"color:#777777\">&#xff08;<\/span><br \/>\n     <span style=\"color:#777777\">size_type n, const value_type&amp; val &#061; value_type()&#xff09;<\/span>\n     <\/td>\n<td style=\"width:197px\">\n<p>     <span style=\"color:#777777\">\u6784\u9020\u5e76\u521d\u59cb\u5316<\/span><br \/>\n     <span style=\"color:#777777\">n<\/span><br \/>\n     <span style=\"color:#777777\">\u4e2a<\/span><br \/>\n     <span style=\"color:#777777\">val<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td style=\"width:401px\">\n<p>     <span style=\"color:#777777\">vector (const vector&amp; x); &#xff08;\u91cd\u70b9&#xff09;<\/span>\n     <\/td>\n<td style=\"width:197px\">\n<p>     <span style=\"color:#777777\">\u62f7\u8d1d\u6784\u9020<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td style=\"width:401px\">\n<p>     <span style=\"color:#777777\">vector (InputIterator first, InputIterator last);<\/span>\n     <\/td>\n<td style=\"width:197px\">\n<p>     <span style=\"color:#777777\">\u4f7f\u7528\u8fed\u4ee3\u5668\u8fdb\u884c\u521d\u59cb\u5316\u6784\u9020<\/span>\n     <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u8fed\u4ee3\u5668\u00a0<\/h3>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:600px\">\n<tbody>\n<tr>\n<td style=\"width:187px\">\n<p>     <span style=\"color:#777777\">iterator<\/span><br \/>\n     <span style=\"color:#777777\">\u7684\u4f7f<\/span><br \/>\n     <span style=\"color:#777777\">\u7528<\/span>\n     <\/td>\n<td style=\"width:411px\">\n<p>     <span style=\"color:#777777\">\u63a5\u53e3\u8bf4\u660e<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td style=\"width:187px\">\n<p>     <span style=\"color:#4183c4\">begin <\/span><br \/>\n     <span style=\"color:#777777\">&#043; <\/span><br \/>\n     <span style=\"color:#4183c4\">end<\/span><br \/>\n     <span style=\"color:#777777\">&#xff08;\u91cd\u70b9&#xff09;<\/span>\n     <\/td>\n<td style=\"width:411px\">\n<p>     <span style=\"color:#777777\">\u83b7\u53d6\u7b2c\u4e00\u4e2a\u6570\u636e\u4f4d\u7f6e\u7684<\/span><br \/>\n     <span style=\"color:#777777\">iterator\/const_iterator<\/span><br \/>\n     <span style=\"color:#777777\">&#xff0c; \u83b7\u53d6\u6700\u540e\u4e00\u4e2a\u6570\u636e\u7684\u4e0b <\/span> <\/p>\n<p>     <span style=\"color:#777777\">\u4e00\u4e2a\u4f4d\u7f6e\u7684<\/span><br \/>\n     <span style=\"color:#777777\">iterator\/const_iterator<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td style=\"width:187px\">\n<p>     <span style=\"color:#4183c4\">rbegin <\/span><br \/>\n     <span style=\"color:#777777\">&#043;\u00a0<\/span><br \/>\n     <span style=\"color:#4183c4\">rend<\/span>\n     <\/td>\n<td style=\"width:411px\">\n<p>     <span style=\"color:#777777\">\u83b7\u53d6\u6700\u540e\u4e00\u4e2a\u6570\u636e\u4f4d\u7f6e\u7684<\/span><br \/>\n     <span style=\"color:#777777\">reverse_iterator<\/span><br \/>\n     <span style=\"color:#777777\">&#xff0c;\u83b7\u53d6\u7b2c\u4e00\u4e2a\u6570\u636e\u524d\u4e00\u4e2a\u4f4d\u7f6e\u7684reverse_iterator<\/span>\n     <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u5bb9\u91cf\u64cd\u4f5c\u00a0<\/h3>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:600px\">\n<tbody>\n<tr>\n<td>\n<p>     <span style=\"color:#777777\">\u5bb9\u91cf\u7a7a\u95f4<\/span>\n     <\/td>\n<td>\n<p>     <span style=\"color:#777777\">\u63a5\u53e3\u8bf4\u660e<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td>\n<p>     <span style=\"color:#4183c4\">size<\/span>\n     <\/td>\n<td>\n<p>     <span style=\"color:#777777\">\u83b7\u53d6\u6570\u636e\u4e2a\u6570<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td>\n<p>     <span style=\"color:#4183c4\">capacity<\/span>\n     <\/td>\n<td>\n<p>     <span style=\"color:#777777\">\u83b7\u53d6\u5bb9\u91cf\u5927\u5c0f<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td>\n<p>     <span style=\"color:#4183c4\">empty<\/span>\n     <\/td>\n<td>\n<p>     <span style=\"color:#777777\">\u5224\u65ad\u662f\u5426\u4e3a\u7a7a<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td>\n<p>     <span style=\"color:#4183c4\">resize<\/span><br \/>\n     <span style=\"color:#777777\">&#xff08;\u91cd\u70b9&#xff09;<\/span>\n     <\/td>\n<td>\n<p>     <span style=\"color:#777777\">\u6539\u53d8<\/span><br \/>\n     <span style=\"color:#777777\">vector<\/span><br \/>\n     <span style=\"color:#777777\">\u7684<\/span><br \/>\n     <span style=\"color:#777777\">size<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td>\n<p>     <span style=\"color:#4183c4\">reserve <\/span><br \/>\n     <span style=\"color:#777777\">&#xff08;\u91cd\u70b9&#xff09;<\/span>\n     <\/td>\n<td>\n<p>     <span style=\"color:#777777\">\u6539\u53d8<\/span><br \/>\n     <span style=\"color:#777777\">vector<\/span><br \/>\n     <span style=\"color:#777777\">\u7684<\/span><br \/>\n     <span style=\"color:#777777\">capacity<\/span>\n     <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u4fee\u6539\u64cd\u4f5c<\/h3>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:600px\">\n<tbody>\n<tr>\n<td>\n<p>     <span style=\"color:#777777\">vector<\/span><br \/>\n     <span style=\"color:#777777\">\u589e\u5220\u67e5\u6539<\/span>\n     <\/td>\n<td>\n<p>     <span style=\"color:#777777\">\u63a5\u53e3\u8bf4\u660e<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td>\n<p>     <span style=\"color:#4183c4\">push_back<\/span><br \/>\n     <span style=\"color:#777777\">&#xff08;\u91cd\u70b9&#xff09;<\/span>\n     <\/td>\n<td>\n<p>     <span style=\"color:#777777\">\u5c3e\u63d2<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td>\n<p>     <span style=\"color:#4183c4\">pop_back <\/span><br \/>\n     <span style=\"color:#777777\">&#xff08;\u91cd\u70b9&#xff09;<\/span>\n     <\/td>\n<td>\n<p>     <span style=\"color:#777777\">\u5c3e\u5220<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td>\n<p>     <span style=\"color:#4183c4\">find<\/span>\n     <\/td>\n<td>\n<p>     <span style=\"color:#777777\">\u67e5\u627e\u3002&#xff08;\u6ce8\u610f\u8fd9\u4e2a\u662f\u7b97\u6cd5\u6a21\u5757\u5b9e\u73b0&#xff0c;\u4e0d\u662f<\/span><br \/>\n     <span style=\"color:#777777\">vector<\/span><br \/>\n     <span style=\"color:#777777\">\u7684\u6210\u5458\u63a5\u53e3&#xff09;<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td>\n<p>     <span style=\"color:#4183c4\">insert<\/span>\n     <\/td>\n<td>\n<p>     <span style=\"color:#777777\">\u5728<\/span><br \/>\n     <span style=\"color:#777777\">position<\/span><br \/>\n     <span style=\"color:#777777\">\u4e4b\u524d\u63d2\u5165<\/span><br \/>\n     <span style=\"color:#777777\">val<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td>\n<p>     <span style=\"color:#4183c4\">erase<\/span>\n     <\/td>\n<td>\n<p>     <span style=\"color:#777777\">\u5220\u9664<\/span><br \/>\n     <span style=\"color:#777777\">position<\/span><br \/>\n     <span style=\"color:#777777\">\u4f4d\u7f6e\u7684\u6570\u636e<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td>\n<p>     <span style=\"color:#4183c4\">swap<\/span>\n     <\/td>\n<td>\n<p>     <span style=\"color:#777777\">\u4ea4\u6362\u4e24\u4e2a<\/span><br \/>\n     <span style=\"color:#777777\">vector\u7684\u6570\u636e\u7a7a\u95f4<\/span>\n     <\/td>\n<\/tr>\n<tr>\n<td>\n<p>     <span style=\"color:#4183c4\">operator[] <\/span><br \/>\n     <span style=\"color:#777777\">&#xff08;\u91cd\u70b9&#xff09;<\/span>\n     <\/td>\n<td>\n<p>     <span style=\"color:#777777\">\u50cf\u6570\u7ec4\u4e00\u6837\u8bbf\u95ee<\/span>\n     <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h2>vector\u5b9e\u73b0<\/h2>\n<h3>\u5e95\u5c42\u7ed3\u6784<\/h3>\n<p>\u5728C\u8bed\u8a00\u5b9e\u73b0\u5f53\u4e2d&#xff0c;vector\u5b9e\u73b0\u4e2d\u5e76\u6ca1\u6709\u8fed\u4ee3\u5668\u7684\u652f\u6301&#xff0c;\u56e0\u6b64\u5e95\u5c42\u7ed3\u6784\u8bbe\u8ba1\u5e76\u4e0d\u590d\u6742\u3002<\/p>\n<p>typedef struct SeqList<br \/>\n{<br \/>\nSLDataType* arr;<br \/>\nint size;\/\/\u6709\u6548\u6570\u636e\u4e2a\u6570<br \/>\nint capacity;\/\/\u7a7a\u95f4\u5927\u5c0f<br \/>\n}SL; <\/p>\n<p><span style=\"color:#fe2c24\">\u4e3a\u4e86\u63d0\u4f9b\u8fed\u4ee3\u5668\u7684\u652f\u6301&#xff0c;\u53ef\u4ee5\u50cf\u6307\u9488\u4e00\u6837\u904d\u5386\u6570\u7ec4&#xff0c;\u56e0\u6b64\u5bf9vector\u7684\u5e95\u5c42\u5c01\u88c5\u91c7\u7528\u5982\u4e0b\u3002<\/span><\/p>\n<p>template&lt;class T&gt;<\/p>\n<p>class vector<br \/>\n{<br \/>\npublic:<br \/>\n    typedef T* iterator;<br \/>\ntypedef const T* const_iterator;<br \/>\n    \/\/&#8230;<\/p>\n<p>private:<br \/>\n\/\/\u7ed9\u7f3a\u7701\u503c<br \/>\niterator _start &#061; nullptr;<br \/>\niterator _finish &#061; nullptr;<br \/>\niterator _end_of_storage &#061; nullptr;<br \/>\n}; <\/p>\n<h3>\u8fed\u4ee3\u5668<\/h3>\n<p>iterator begin()<br \/>\n{<br \/>\nreturn _start;<br \/>\n}<\/p>\n<p>iterator end()<br \/>\n{<br \/>\nreturn _finish;<br \/>\n}<\/p>\n<p>const_iterator begin() const<br \/>\n{<br \/>\nreturn _start;<br \/>\n}<\/p>\n<p>const_iterator end() const<br \/>\n{<br \/>\nreturn _finish;<br \/>\n} <\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"196\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042639-6839337f3454d.png\" width=\"601\" \/><\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"267\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042639-6839337f46567.png\" width=\"916\" \/><\/p>\n<hr \/>\n<h3>memcpy\u62f7\u8d1d\u95ee\u9898<\/h3>\n<p>void reserve(size_t n)<br \/>\n{<br \/>\nif (n &gt; capacity())<br \/>\n{<br \/>\nsize_t oldsize &#061; size();<br \/>\nT* tmp &#061; new T[n];<br \/>\nmemcpy(tmp, _start, sizeof(T) * oldsize);<br \/>\ndelete[] _start;<\/p>\n<p>_start &#061; tmp;<br \/>\n_finish &#061; _start &#043; oldsize;<br \/>\n_end_of_storage &#061; _start &#043; n;<br \/>\n}<br \/>\n} <\/p>\n<p>\u5b9e\u9645\u4e0a&#xff0c;\u4e0a\u9762\u8fd9\u6bb5\u7a0b\u5e8f\u5728\u5185\u7f6e\u7c7b\u578b\u662f\u4e0d\u4f1a\u51fa\u95ee\u9898\u7684&#xff0c;\u4f46\u662f\u9488\u5bf9\u4e00\u4e9b\u573a\u666f&#xff08;\u5982\u81ea\u5b9a\u4e49\u7c7b\u578b&#xff09;\u4f1a\u62a5\u9519&#xff0c;\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1888\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042639-6839337f630f4.png\" width=\"912\" \/><\/p>\n<p>\u5982\u679cvector\u4e2d\u5b58\u7684\u662f\u81ea\u5b9a\u4e49\u7c7b\u578b<\/p>\n<p><span style=\"color:#fe2c24\">\u95ee\u98981&#xff1a;\u4f1a\u5bfc\u81f4\u591a\u6b21\u6790\u6784&#xff1b;<\/span><\/p>\n<p><span style=\"color:#fe2c24\">\u95ee\u98982&#xff1a;\u4e00\u4e2a\u6570\u636e\u7684\u4fee\u6539\u4f1a\u5f71\u54cd\u53e6\u4e00\u4e2a \u3002<\/span><\/p>\n<p><span style=\"color:#fe2c24\">\u95ee\u98983&#xff1a;memcpy\u5219\u53ea\u80fd\u62f7\u8d1d\u6bcf\u4e2astring,\u4f46\u8fd8\u662f\u540c\u6837\u6307\u5411\u540c\u4e00\u4e2a\u4e32\u3002<\/span><\/p>\n<p>\u4e3a\u4e86\u9632\u6b62\u6d45\u62f7\u8d1d\u95ee\u9898&#xff0c;\u5982\u4e0b\u7a0b\u5e8f\u662f\u9488\u5bf9\u81ea\u5b9a\u4e49\u7c7b\u578b\u7684\u4f18\u5316\u3002<\/p>\n<p>void reserve(size_t n)<br \/>\n{<br \/>\nif (n &gt; capacity())<br \/>\n{<br \/>\nsize_t oldsize &#061; size();<br \/>\nT* tmp &#061; new T[n];<br \/>\n\/\/memcpy(tmp, _start, sizeof(T) * oldsize); \/\/err\u53ea\u80fd\u9488\u5bf9\u5185\u7f6e\u7c7b\u578b<\/p>\n<p>for (size_t i &#061; 0;i &lt; oldsize;&#043;&#043;i)<br \/>\n{<br \/>\ntmp[i] &#061; _start[i];<br \/>\n\/\/\u5185\u7f6e\u7c7b\u578b\u4e0d\u4f1a\u6709\u95ee\u9898<br \/>\n\/\/\u81ea\u5b9a\u4e49\u7c7b\u578b\u8c03\u7528\u5176&#061;\u8fd0\u7b97\u7b26\u91cd\u8f7d\u51fd\u6570\u8d70\u6df1\u62f7\u8d1d,\u9632\u6b62memcpy\u51fa\u73b0\u7684\u95ee\u9898<br \/>\n}<br \/>\ndelete[] _start;<\/p>\n<p>_start &#061; tmp;<br \/>\n_finish &#061; _start &#043; oldsize;<br \/>\n_end_of_storage &#061; _start &#043; n;<br \/>\n}<br \/>\n} <\/p>\n<p> <span style=\"color:#956fe7\">\u7ed3\u8bba&#xff1a;\u5982\u679c\u5bf9\u8c61\u4e2d\u6d89\u53ca\u5230\u8d44\u6e90\u7ba1\u7406\u65f6&#xff0c;\u5343\u4e07\u4e0d\u80fd\u4f7f\u7528memcpy\u8fdb\u884c\u5bf9\u8c61\u4e4b\u95f4\u7684\u62f7\u8d1d&#xff0c;\u56e0\u4e3a <\/span> <\/p>\n<p> <span style=\"color:#956fe7\">memcpy\u662f\u6d45\u62f7\u8d1d&#xff0c;\u5426\u5219\u53ef\u80fd\u4f1a\u5f15\u8d77\u5185\u5b58\u6cc4\u6f0f\u751a\u81f3\u7a0b\u5e8f\u5d29\u6e83\u3002<\/span> <\/p>\n<hr \/>\n<h3 style=\"background-color:transparent\">\u8fed\u4ee3\u5668\u5931\u6548\u95ee\u9898<\/h3>\n<p> <span style=\"color:#777777\">\u8fed\u4ee3\u5668\u7684\u4e3b\u8981\u4f5c\u7528\u5c31\u662f\u8ba9\u7b97\u6cd5\u80fd\u591f\u4e0d\u7528\u5173\u5fc3\u5e95\u5c42\u6570\u636e\u7ed3\u6784&#xff0c;\u5176\u5e95\u5c42\u5b9e\u9645\u5c31\u662f\u4e00\u4e2a\u6307\u9488&#xff0c;\u6216\u8005\u662f\u5bf9 <\/span> <\/p>\n<p> <span style=\"color:#777777\">\u6307\u9488\u8fdb\u884c\u4e86\u5c01\u88c5<\/span><br \/>\n <span style=\"color:#777777\">&#xff0c;\u6bd4\u5982&#xff1a;<\/span><br \/>\n <span style=\"color:#777777\">vector<\/span><br \/>\n <span style=\"color:#777777\">\u7684\u8fed\u4ee3\u5668\u5c31\u662f\u539f\u751f\u6001\u6307\u9488<\/span><br \/>\n <span style=\"color:#777777\">T* <\/span><br \/>\n <span style=\"color:#777777\">\u3002\u56e0\u6b64<\/span><br \/>\n <span style=\"color:#777777\">\u8fed\u4ee3\u5668\u5931\u6548&#xff0c;\u5b9e\u9645\u5c31\u662f\u8fed\u4ee3\u5668 <\/span> <\/p>\n<p> <span style=\"color:#777777\">\u5e95\u5c42\u5bf9\u5e94\u6307\u9488\u6240\u6307\u5411\u7684\u7a7a\u95f4\u88ab\u9500\u6bc1\u4e86&#xff0c;\u800c\u4f7f\u7528\u4e00\u5757\u5df2\u7ecf\u88ab\u91ca\u653e\u7684\u7a7a\u95f4<\/span><br \/>\n <span style=\"color:#777777\">&#xff0c;\u9020\u6210\u7684\u540e\u679c\u662f\u7a0b\u5e8f\u5d29\u6e83<\/span><br \/>\n <span style=\"color:#777777\">(<\/span><br \/>\n <span style=\"color:#777777\">\u5373 <\/span> <\/p>\n<p> <span style=\"color:#777777\">\u5982\u679c\u7ee7\u7eed\u4f7f\u7528\u5df2\u7ecf\u5931\u6548\u7684\u8fed\u4ee3\u5668&#xff0c;\u7a0b\u5e8f\u53ef\u80fd\u4f1a\u5d29\u6e83<\/span><br \/>\n <span style=\"color:#777777\">)<\/span><br \/>\n <span style=\"color:#777777\">\u3002 <\/span> <\/p>\n<p> <span style=\"color:#777777\">\u5bf9\u4e8e<\/span><br \/>\n <span style=\"color:#777777\">vector<\/span><br \/>\n <span style=\"color:#777777\">\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5176\u8fed\u4ee3\u5668\u5931\u6548\u7684\u64cd\u4f5c\u6709&#xff1a; <\/span> <\/p>\n<p> <span style=\"color:#777777\">1. <\/span><br \/>\n <span style=\"color:#777777\">\u4f1a\u5f15\u8d77\u5176\u5e95\u5c42\u7a7a\u95f4\u6539\u53d8\u7684\u64cd\u4f5c&#xff0c;\u90fd\u6709\u53ef\u80fd\u662f\u8fed\u4ee3\u5668\u5931\u6548<\/span><br \/>\n <span style=\"color:#777777\">&#xff0c;\u6bd4\u5982&#xff1a;<\/span><br \/>\n <span style=\"color:#777777\">resize<\/span><br \/>\n <span style=\"color:#777777\">\u3001<\/span><br \/>\n <span style=\"color:#777777\">reserve<\/span><br \/>\n <span style=\"color:#777777\">\u3001<\/span><br \/>\n <span style=\"color:#777777\">insert<\/span><br \/>\n <span style=\"color:#777777\">\u3001 <\/span> <\/p>\n<p> <span style=\"color:#777777\">assign<\/span><br \/>\n <span style=\"color:#777777\">\u3001<\/span><br \/>\n <span style=\"color:#777777\">push_back<\/span><br \/>\n <span style=\"color:#777777\">\u7b49\u3002<\/span> <\/p>\n<p> void insert(iterator pos, const T&amp; x)<br \/>\n{<br \/>\nassert(pos &lt; _finish);<br \/>\nassert(pos &gt;&#061; _start);<\/p>\n<p>if (size() &#061;&#061; capacity())<br \/>\n{<br \/>\nreserve(capacity() &#061;&#061; 0 ? 4 : 2 * capacity());<br \/>\n}<\/p>\n<p>iterator it &#061; _finish &#8211; 1;<br \/>\nwhile (it &gt;&#061; pos)<br \/>\n{<br \/>\n*(it &#043; 1) &#061; *it;<br \/>\n&#8211;it;<br \/>\n}<\/p>\n<p>*pos &#061; x;<br \/>\n&#043;&#043;_finish;<br \/>\n} <\/p>\n<p>\u00a0\u5728\u4e0a\u9762\u8fd9\u6bb5\u7a0b\u5e8f\u4e2d&#xff0c;\u7531\u4e8e\u5bb9\u91cf\u6ee1\u4e86\u9700\u8981\u8fdb\u884c\u6269\u5bb9&#xff0c;<span style=\"color:#fe2c24\">\u5f00\u8f9f\u4e00\u6bb5\u65b0\u7a7a\u95f4<\/span>&#xff0c;\u5c06\u65e7\u7a7a\u95f4\u7684\u5143\u7d20\u62f7\u8d1d\u5230\u65b0\u7a7a\u95f4\u4e0a\u6765&#xff0c;\u5e76\u66f4\u65b0_start&#xff0c;_finish&#xff0c;_end_of_storage\u3002\u4f46\u5982\u679c<span style=\"color:#fe2c24\">\u8fed\u4ee3\u5668it\u6307\u5411\u65e7\u7a7a\u95f4\u4e0a\u7684\u5f00\u59cb\u4f4d\u7f6e<\/span>&#xff0c;\u6b64\u65f6\u8fdb\u884c<span style=\"color:#fe2c24\">*it\u4f1a\u5bfc\u81f4\u91ce\u6307\u9488\u89e3\u5f15\u7528\u95ee\u9898<\/span>&#xff0c;\u8fd9\u4e5f\u5c31\u662f\u6240\u8c13\u5730<span style=\"color:#956fe7\">\u8fed\u4ee3\u5668\u5931\u6548\u4e86\u3002<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"313\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042640-683933803336e.png\" width=\"855\" \/><\/p>\n<\/p>\n<p>\u90a3\u8be5\u5982\u4f55\u89e3\u51b3\u5462&#xff1f;\u66f4\u65b0\u8fed\u4ee3\u5668\u6307\u5411\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>void insert(iterator pos, const T&amp; x)<br \/>\n{<br \/>\nassert(pos &lt; _finish);<br \/>\nassert(pos &gt;&#061; _start);<\/p>\n<p>    \/\/\u9632\u6b62\u8fed\u4ee3\u5668\u5931\u6548<br \/>\nif (size() &#061;&#061; capacity())<br \/>\n{<br \/>\nsize_t len &#061; pos &#8211; _start;<br \/>\nreserve(capacity() &#061;&#061; 0 ? 4 : 2 * capacity());<br \/>\npos &#061; _start &#043; len;<br \/>\n}<\/p>\n<p>\/\/&#8230;<br \/>\n}<\/p>\n<p>\u66f4\u65b0\u4e86\u8fed\u4ee3\u5668\u4f4d\u7f6e\u540e&#xff0c;\u89e3\u5f15\u7528\u8fd8\u662f\u4f1a\u62a5\u9519&#xff0c;\u8fd9\u662f\u4e3a\u4ec0\u4e48\u5462&#xff1f;\u8fd9\u91cc\u770b\u4f3c\u89e3\u51b3\u4e86\u95ee\u9898&#xff0c;\u4f46\u662f\u522b\u5fd8\u4e86<span style=\"color:#4da8ee\">\u5f62\u53c2\u7684\u6539\u53d8\u5e76\u4e0d\u80fd\u5f71\u54cd\u5b9e\u53c2<\/span>&#xff0c;\u5373\u5b9e\u53c2\u4e2d\u7684\u8fed\u4ee3\u5668\u4f9d\u7136\u6307\u5411\u65e7\u7a7a\u95f4\u7684\u4f4d\u7f6e&#xff0c;<span style=\"color:#38d8f0\">\u4f9d\u65e7\u4f1a\u4f7f\u8fed\u4ee3\u5668\u5931\u6548<\/span>\u3002\u90a3\u6211\u8ba9\u5f62\u53c2\u7684\u6539\u53d8\u5f71\u54cd\u5b9e\u53c2\u53ef\u884c\u5417&#xff0c;\u5373\u52a0\u4e0a\u5f15\u7528\u5462&#xff1f;<\/p>\n<p>void insert(iterator&amp; pos, const T&amp; x) <\/p>\n<p>\u800c\u6211\u4eec\u8bbe\u8ba1\u521d\u5fc3\u662f\u60f3\u8981pos\u53ef\u4ee5\u968f\u610f\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u5143\u7d20&#xff0c;\u5f53\u60f3\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u7b2c\u4e09\u4e2a\u5143\u7d20\u65f6<\/p>\n<p>v.insert(v.begin()&#043;3,3); <\/p>\n<p>\u00a0\u7531\u4e8e\u662f\u5de6\u503c\u5f15\u7528\u53f3\u503c&#xff0c;\u9700\u8981\u662fconst\u5de6\u503c\u5f15\u7528\u624d\u80fd\u5f15\u7528\u53f3\u503c&#xff0c;\u90a3\u4e48\u518d\u8fdb\u884c\u66f4\u6539\u3002<\/p>\n<p>void insert(const iterator&amp; pos, const T&amp; x) <\/p>\n<p>\u8fd9\u91cc\u4f1a\u53d1\u73b0\u7531\u4e8e<span style=\"color:#fe2c24\">const\u7684\u4fee\u9970&#xff0c;\u4f1a\u5bfc\u81f4insert\u51fd\u6570\u5185\u90e8\u662f\u65e0\u6cd5\u4fee\u6539\u8fed\u4ee3\u5668pos\u4f4d\u7f6e\u7684<\/span>&#xff0c;\u56e0\u6b64\u8fd9\u79cd\u65b9\u6848\u4e5f\u662f\u4e0d\u53ef\u53d6\u7684\u3002<\/p>\n<p><span style=\"color:#fe2c24\">\u603b\u4e4b&#xff0c;insert\u4ee5\u540e&#xff0c;\u9ed8\u8ba4\u8fed\u4ee3\u5668\u90fd\u5931\u6548\u4e86<\/span>&#xff08;\u5c3d\u7ba1\u5728insert\u51fd\u6570\u91cc\u4fee\u590d\u4e86\u8fed\u4ee3\u5668\u6307\u5411\u4f4d\u7f6e&#xff0c;\u4f46\u7531\u4e8e\u5f62\u53c2\u5e76\u4e0d\u4f1a\u5b9e\u53c2&#xff09;\u3002<\/p>\n<hr \/>\n<p>  <span style=\"color:#777777\">2. <\/span><br \/>\n  <span style=\"color:#777777\">\u6307\u5b9a\u4f4d\u7f6e\u5143\u7d20\u7684\u5220\u9664\u64cd\u4f5c &#8211;&gt;\u00a0<\/span><br \/>\n  <span style=\"color:#777777\">erase<\/span> <\/p>\n<p>  void erase(iterator pos)<br \/>\n{<br \/>\nassert(pos &lt; _finish);<br \/>\nassert(pos &gt;&#061; _start);<\/p>\n<p>iterator it &#061; pos &#043; 1;<br \/>\nwhile (it &lt; _finish)<br \/>\n{<br \/>\n*(it &#8211; 1) &#061; *it;<br \/>\n&#043;&#043;it;<br \/>\n}<br \/>\n  &#8211;_finish;<br \/>\n} <\/p>\n<p>\u8fd9\u91cc\u7684\u5220\u9664\u4f9d\u7136\u5b58\u5728\u7740\u4e00\u4e2a\u9690\u79d8\u7684\u95ee\u9898 &#8211;&gt;\u90a3\u5b83\u53c8\u662f\u5982\u4f55\u5bfc\u81f4\u7684\u5462&#xff1f;<\/p>\n<p>  auto it &#061; v1.begin();<br \/>\nwhile (it !&#061; v1.end())<br \/>\n{<br \/>\nif (*it % 2 &#061;&#061; 0)<br \/>\n{<br \/>\nv1.erase(it);<br \/>\n}<\/p>\n<p>&#043;&#043;it;<br \/>\n} <\/p>\n<p>   <span style=\"color:#777777\">erase<\/span><br \/>\n   <span style=\"color:#777777\">\u5220\u9664<\/span><br \/>\n   <span style=\"color:#777777\">pos<\/span><br \/>\n   <span style=\"color:#777777\">\u4f4d\u7f6e\u5143\u7d20\u540e&#xff0c;<\/span><br \/>\n   <span style=\"color:#777777\">pos<\/span><br \/>\n   <span style=\"color:#777777\">\u4f4d\u7f6e\u4e4b\u540e\u7684\u5143\u7d20\u4f1a\u5f80\u524d\u642c\u79fb&#xff0c;\u6ca1\u6709\u5bfc\u81f4\u5e95\u5c42\u7a7a\u95f4\u7684\u6539\u53d8&#xff0c;<\/span><br \/>\n   <span style=\"color:#fe2c24\">\u7406 <\/span> <\/p>\n<p>   <span style=\"color:#fe2c24\">\u8bba\u4e0a\u8bb2\u8fed\u4ee3\u5668\u4e0d\u5e94\u8be5\u4f1a\u5931\u6548<\/span><br \/>\n   <span style=\"color:#777777\">&#xff0c;\u4f46\u662f&#xff1a;\u5982\u679c<\/span><br \/>\n   <span style=\"color:#777777\">pos<\/span><br \/>\n   <span style=\"color:#777777\">\u521a\u597d\u662f\u6700\u540e\u4e00\u4e2a\u5143\u7d20&#xff0c;<\/span><br \/>\n   <span style=\"color:#fe2c24\">\u5220\u5b8c\u4e4b\u540epos\u521a\u597d\u662fend <\/span> <\/p>\n<p>   <span style=\"color:#fe2c24\">\u7684\u4f4d\u7f6e&#xff0c;\u800cend\u4f4d\u7f6e\u662f\u6ca1\u6709\u5143\u7d20\u7684&#xff0c;\u90a3\u4e48pos\u5c31\u5931\u6548\u4e86<\/span><span style=\"color:#956fe7\">&#xff08;\u5373it\u548c_finish\u521a\u597d\u9519\u8fc7\u4e86&#xff0c;\u5faa\u73af\u5224\u65ad\u4f9d\u7136\u6210\u7acb&#xff0c;\u6b64\u65f6\u7ee7\u7eed\u6267\u884c\u4f1a\u51fa\u73b0\u9519\u8bef&#xff09;\u3002<\/span> <\/p>\n<p>   <img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"440\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042640-683933805d891.png\" width=\"601\" \/> <\/p>\n<p>    \u6309\u7167\u4e0a\u9762\u7684\u8bf4\u6cd5&#xff0c;\u90a3\u4e48\u6539\u4e0b\u5224\u65ad\u6761\u4ef6\u4e0d\u5c31\u80fd\u4f7fit\u7b49\u4e8e_finish\u4e86\u5417&#xff1f;&#xff08;\u5982\u4e0b\u4ee3\u7801\u6240\u793a&#xff09;\u4f46\u8fd0\u884c\u4e4b\u540e\u4f9d\u7136\u4f1a\u62a5\u9519&#xff0c;\u8fd9\u662f\u56e0\u4e3a<br \/>\n   <span style=\"color:#777777\">\u5220\u9664<\/span><br \/>\n   <span style=\"color:#777777\">vector\u4e2d\u4efb\u610f\u4f4d\u7f6e\u4e0a\u5143\u7d20\u65f6&#xff0c;vs\u5c31\u8ba4\u4e3a\u8be5\u4f4d\u7f6e\u8fed\u4ee3\u5668\u5931\u6548\u4e86&#xff0c;\u5373\u5728<\/span><br \/>\n   <span style=\"color:#fe2c24\">vs\u4e0b\u68c0\u67e5\u4e25\u683c<\/span><br \/>\n   <span style=\"color:#777777\">\u3002&#xff08;Linux<\/span><br \/>\n   <span style=\"color:#777777\">\u4e0b&#xff0c;<\/span><br \/>\n   <span style=\"color:#777777\">g&#043;&#043;<\/span><br \/>\n   <span style=\"color:#777777\">\u7f16\u8bd1\u5668\u5bf9\u8fed\u4ee3\u5668\u5931\u6548\u7684\u68c0\u6d4b\u5e76\u4e0d\u662f\u975e\u5e38\u4e25\u683c&#xff0c;\u5904\u7406\u4e5f\u6ca1\u6709<\/span><br \/>\n   <span style=\"color:#777777\">vs<\/span><br \/>\n   <span style=\"color:#777777\">\u4e0b\u6781\u7aef&#xff09;<\/span> <\/p>\n<p>   auto it &#061; v1.begin();<br \/>\nwhile (it !&#061; v1.end())<br \/>\n{<br \/>\nif (*it % 2 &#061;&#061; 0)<br \/>\n{<br \/>\nv1.erase(it);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\n&#043;&#043;it;<br \/>\n}<br \/>\n} <\/p>\n<p>\u56e0\u6b64&#xff0c;\u4f7f\u7528<span style=\"color:#fe2c24\">erase\u63a5\u53e3<\/span>\u65f6\u5e76\u4e0d\u80fd\u4f9d\u8d56\u4e8e\u7f16\u8bd1\u5668&#xff0c;\u5e94\u6ce8\u610f\u9700\u8981<span style=\"color:#fe2c24\">\u624b\u52a8\u66f4\u65b0\u8fed\u4ee3\u5668\u9632\u6b62\u8fed\u4ee3\u5668\u5931\u6548\u95ee\u9898<\/span>\u3002<\/p>\n<p>\u5728stl\u5e93\u4e2d\u4e5f\u662f\u8fd9\u4e48\u89e3\u51b3\u7684\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"162\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042640-6839338079c00.png\" width=\"601\" \/><\/p>\n<p>    <span style=\"color:#777777\">\u8fed\u4ee3\u5668\u5931\u6548\u89e3\u51b3\u529e\u6cd5&#xff1a;\u5728\u4f7f\u7528\u524d&#xff0c;\u5bf9\u8fed\u4ee3\u5668\u91cd\u65b0\u8d4b\u503c\u5373\u53ef<\/span><br \/>\n    <span style=\"color:#777777\">\u3002<\/span> <\/p>\n<p>   auto it &#061; v1.begin();<br \/>\nwhile (it !&#061; v1.end())<br \/>\n{<br \/>\nif (*it % 2 &#061;&#061; 0)<br \/>\n{<br \/>\nit &#061; v1.erase(it);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\n&#043;&#043;it;<br \/>\n}<br \/>\n} <\/p>\n<p><span style=\"color:#777777\">3. <\/span><span style=\"color:#777777\">\u4e0e<\/span><span style=\"color:#777777\">vector<\/span><span style=\"color:#777777\">\u7c7b\u4f3c&#xff0c;<\/span><span style=\"color:#777777\">string<\/span><span style=\"color:#777777\">\u5728\u63d2\u5165<\/span><span style=\"color:#777777\">&#043;<\/span><span style=\"color:#777777\">\u6269\u5bb9\u64cd\u4f5c<\/span><span style=\"color:#777777\">&#043;erase<\/span><span style=\"color:#777777\">\u4e4b\u540e&#xff0c;\u8fed\u4ee3\u5668\u4e5f\u4f1a\u5931\u6548<\/span>\u00a0<\/p>\n<\/p>\n<p><span style=\"color:#fe2c24\">\u603b\u7684\u6765\u8bf4&#xff1a;vector\u7279\u522b\u9700\u8981\u6ce8\u610f\u7684\u662f\u5728\u4f7f\u7528insert\u548cerase\u63a5\u53e3\u5e94\u6ce8\u610f\u8fed\u4ee3\u5668\u5931\u6548\u95ee\u9898&#xff0c;\u8fd9\u6837\u624d\u80fd\u8ba9\u6211\u4eec\u5728\u4f7f\u7528stl\u5e93\u63a5\u53e3\u65f6\u5e94\u5bf9\u81ea\u5982\u3002<\/span><\/p>\n<hr \/>\n<h3>initializer_list\u5b9e\u73b0<\/h3>\n<p>void push_back(const T&amp; x)<br \/>\n{<br \/>\nif (size() &#061;&#061; capacity())<br \/>\n{<br \/>\nreserve(capacity() &#061;&#061; 0 ? 4 : 2 * capacity());<br \/>\n}<br \/>\n*_finish &#061; x;<br \/>\n_finish&#043;&#043;;<br \/>\n}<\/p>\n<p>vector(initializer_list&lt;T&gt; il)<br \/>\n{<br \/>\nreserve(il.size());<br \/>\nfor (auto&amp; ch : il)<br \/>\n{<br \/>\npush_back(ch);<br \/>\n}<br \/>\n} <\/p>\n<hr \/>\n<p>\u00a0<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"400\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042640-683933808b773.png\" width=\"1315\" \/><\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042640-68393380ddb44.gif\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.4k\u6b21\uff0c\u70b9\u8d5e128\u6b21\uff0c\u6536\u85cf114\u6b21\u3002\u672c\u7ae0\u8282\u57fa\u672c\u4ecb\u7ecd\u4e86vector\u7684\u5e38\u89c1\u63a5\u53e3\u4ee5\u53cavector\u7c7b\u7684\u4ee3\u7801\u5b9e\u73b0\uff0c\u91cd\u70b9\u5728\u4e8e\u5b9e\u73b0vector\u51fa\u73b0\u7684\u8fed\u4ee3\u5668\u5931\u6548\u95ee\u9898\u3002<\/p>\n","protected":false},"author":2,"featured_media":40917,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,3752,2762,190,1813,3753],"topic":[],"class_list":["post-40926","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-c11","tag-vector","tag-190","tag-1813","tag-3753"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010C++\u6307\u5357\u3011STL\u5bb9\u5668\u7684\u5b89\u5168\u9769\u547d\uff1a\u5982\u4f55\u5c01\u88c5Vector\u675c\u7edd\u8d8a\u754c\u8bbf\u95ee\u4e0e\u8fed\u4ee3\u5668\u5931\u6548\uff1f - \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\/40926.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010C++\u6307\u5357\u3011STL\u5bb9\u5668\u7684\u5b89\u5168\u9769\u547d\uff1a\u5982\u4f55\u5c01\u88c5Vector\u675c\u7edd\u8d8a\u754c\u8bbf\u95ee\u4e0e\u8fed\u4ee3\u5668\u5931\u6548\uff1f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.4k\u6b21\uff0c\u70b9\u8d5e128\u6b21\uff0c\u6536\u85cf114\u6b21\u3002\u672c\u7ae0\u8282\u57fa\u672c\u4ecb\u7ecd\u4e86vector\u7684\u5e38\u89c1\u63a5\u53e3\u4ee5\u53cavector\u7c7b\u7684\u4ee3\u7801\u5b9e\u73b0\uff0c\u91cd\u70b9\u5728\u4e8e\u5b9e\u73b0vector\u51fa\u73b0\u7684\u8fed\u4ee3\u5668\u5931\u6548\u95ee\u9898\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/40926.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-30T04:26:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042638-6839337ee0fef.jpg\" \/>\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=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/40926.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/40926.html\",\"name\":\"\u3010C++\u6307\u5357\u3011STL\u5bb9\u5668\u7684\u5b89\u5168\u9769\u547d\uff1a\u5982\u4f55\u5c01\u88c5Vector\u675c\u7edd\u8d8a\u754c\u8bbf\u95ee\u4e0e\u8fed\u4ee3\u5668\u5931\u6548\uff1f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-30T04:26:41+00:00\",\"dateModified\":\"2025-05-30T04:26:41+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/40926.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/40926.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/40926.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010C++\u6307\u5357\u3011STL\u5bb9\u5668\u7684\u5b89\u5168\u9769\u547d\uff1a\u5982\u4f55\u5c01\u88c5Vector\u675c\u7edd\u8d8a\u754c\u8bbf\u95ee\u4e0e\u8fed\u4ee3\u5668\u5931\u6548\uff1f\"}]},{\"@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":"\u3010C++\u6307\u5357\u3011STL\u5bb9\u5668\u7684\u5b89\u5168\u9769\u547d\uff1a\u5982\u4f55\u5c01\u88c5Vector\u675c\u7edd\u8d8a\u754c\u8bbf\u95ee\u4e0e\u8fed\u4ee3\u5668\u5931\u6548\uff1f - \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\/40926.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010C++\u6307\u5357\u3011STL\u5bb9\u5668\u7684\u5b89\u5168\u9769\u547d\uff1a\u5982\u4f55\u5c01\u88c5Vector\u675c\u7edd\u8d8a\u754c\u8bbf\u95ee\u4e0e\u8fed\u4ee3\u5668\u5931\u6548\uff1f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.4k\u6b21\uff0c\u70b9\u8d5e128\u6b21\uff0c\u6536\u85cf114\u6b21\u3002\u672c\u7ae0\u8282\u57fa\u672c\u4ecb\u7ecd\u4e86vector\u7684\u5e38\u89c1\u63a5\u53e3\u4ee5\u53cavector\u7c7b\u7684\u4ee3\u7801\u5b9e\u73b0\uff0c\u91cd\u70b9\u5728\u4e8e\u5b9e\u73b0vector\u51fa\u73b0\u7684\u8fed\u4ee3\u5668\u5931\u6548\u95ee\u9898\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/40926.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-30T04:26:41+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042638-6839337ee0fef.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/40926.html","url":"https:\/\/www.wsisp.com\/helps\/40926.html","name":"\u3010C++\u6307\u5357\u3011STL\u5bb9\u5668\u7684\u5b89\u5168\u9769\u547d\uff1a\u5982\u4f55\u5c01\u88c5Vector\u675c\u7edd\u8d8a\u754c\u8bbf\u95ee\u4e0e\u8fed\u4ee3\u5668\u5931\u6548\uff1f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-30T04:26:41+00:00","dateModified":"2025-05-30T04:26:41+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/40926.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/40926.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/40926.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010C++\u6307\u5357\u3011STL\u5bb9\u5668\u7684\u5b89\u5168\u9769\u547d\uff1a\u5982\u4f55\u5c01\u88c5Vector\u675c\u7edd\u8d8a\u754c\u8bbf\u95ee\u4e0e\u8fed\u4ee3\u5668\u5931\u6548\uff1f"}]},{"@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\/40926","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=40926"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/40926\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/40917"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=40926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=40926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=40926"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=40926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}