• <i id='kZ7Cb'><tr id='kZ7Cb'><dt id='kZ7Cb'><q id='kZ7Cb'><span id='kZ7Cb'><b id='kZ7Cb'><form id='kZ7Cb'><ins id='kZ7Cb'></ins><ul id='kZ7Cb'></ul><sub id='kZ7Cb'></sub></form><legend id='kZ7Cb'></legend><bdo id='kZ7Cb'><pre id='kZ7Cb'><center id='kZ7Cb'></center></pre></bdo></b><th id='kZ7Cb'></th></span></q></dt></tr></i><div id='kZ7Cb'><tfoot id='kZ7Cb'></tfoot><dl id='kZ7Cb'><fieldset id='kZ7Cb'></fieldset></dl></div>
    <legend id='kZ7Cb'><style id='kZ7Cb'><dir id='kZ7Cb'><q id='kZ7Cb'></q></dir></style></legend>

    <small id='kZ7Cb'></small><noframes id='kZ7Cb'>

        • <bdo id='kZ7Cb'></bdo><ul id='kZ7Cb'></ul>
        <tfoot id='kZ7Cb'></tfoot>

        如何从 std::vector&lt;&gt; 中擦除元素按索引

        时间:2023-09-15

        • <bdo id='4vJR5'></bdo><ul id='4vJR5'></ul>
          <i id='4vJR5'><tr id='4vJR5'><dt id='4vJR5'><q id='4vJR5'><span id='4vJR5'><b id='4vJR5'><form id='4vJR5'><ins id='4vJR5'></ins><ul id='4vJR5'></ul><sub id='4vJR5'></sub></form><legend id='4vJR5'></legend><bdo id='4vJR5'><pre id='4vJR5'><center id='4vJR5'></center></pre></bdo></b><th id='4vJR5'></th></span></q></dt></tr></i><div id='4vJR5'><tfoot id='4vJR5'></tfoot><dl id='4vJR5'><fieldset id='4vJR5'></fieldset></dl></div>
              <tbody id='4vJR5'></tbody>

                <tfoot id='4vJR5'></tfoot>

                <small id='4vJR5'></small><noframes id='4vJR5'>

                <legend id='4vJR5'><style id='4vJR5'><dir id='4vJR5'><q id='4vJR5'></q></dir></style></legend>
                • 本文介绍了如何从 std::vector&lt;&gt; 中擦除元素按索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个 std::vector,我想删除第 n 个元素.我该怎么做?

                  I have a std::vector<int>, and I want to delete the n'th element. How do I do that?

                  std::vector<int> vec;
                  
                  vec.push_back(6);
                  vec.push_back(-17);
                  vec.push_back(12);
                  
                  vec.erase(???);
                  

                  推荐答案

                  要删除单个元素,您可以:

                  To delete a single element, you could do:

                  std::vector<int> vec;
                  
                  vec.push_back(6);
                  vec.push_back(-17);
                  vec.push_back(12);
                  
                  // Deletes the second element (vec[1])
                  vec.erase(std::next(vec.begin()));
                  

                  或者,一次删除多个元素:

                  Or, to delete more than one element at once:

                  // Deletes the second through third elements (vec[1], vec[2])
                  vec.erase(std::next(vec.begin(), 1), std::next(vec.begin(), 3));
                  

                  这篇关于如何从 std::vector&lt;&gt; 中擦除元素按索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:删除循环内向量的元素 下一篇:C++11 和 Boost.Container 下 vector::resize(size_type n) 的这

                  相关文章

                  最新文章

                  <i id='4NQwV'><tr id='4NQwV'><dt id='4NQwV'><q id='4NQwV'><span id='4NQwV'><b id='4NQwV'><form id='4NQwV'><ins id='4NQwV'></ins><ul id='4NQwV'></ul><sub id='4NQwV'></sub></form><legend id='4NQwV'></legend><bdo id='4NQwV'><pre id='4NQwV'><center id='4NQwV'></center></pre></bdo></b><th id='4NQwV'></th></span></q></dt></tr></i><div id='4NQwV'><tfoot id='4NQwV'></tfoot><dl id='4NQwV'><fieldset id='4NQwV'></fieldset></dl></div>

                  <small id='4NQwV'></small><noframes id='4NQwV'>

                • <legend id='4NQwV'><style id='4NQwV'><dir id='4NQwV'><q id='4NQwV'></q></dir></style></legend>
                    <bdo id='4NQwV'></bdo><ul id='4NQwV'></ul>

                    1. <tfoot id='4NQwV'></tfoot>