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

    • <bdo id='RsULs'></bdo><ul id='RsULs'></ul>
    <legend id='RsULs'><style id='RsULs'><dir id='RsULs'><q id='RsULs'></q></dir></style></legend>
  • <tfoot id='RsULs'></tfoot>

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

      1. 如何从具有特定值的 stl 向量中删除项目?

        How do I remove an item from a stl vector with a certain value?(如何从具有特定值的 stl 向量中删除项目?)

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

              <tbody id='yWSUB'></tbody>
          1. <tfoot id='yWSUB'></tfoot>

              • <bdo id='yWSUB'></bdo><ul id='yWSUB'></ul>

              • <legend id='yWSUB'><style id='yWSUB'><dir id='yWSUB'><q id='yWSUB'></q></dir></style></legend>

                <i id='yWSUB'><tr id='yWSUB'><dt id='yWSUB'><q id='yWSUB'><span id='yWSUB'><b id='yWSUB'><form id='yWSUB'><ins id='yWSUB'></ins><ul id='yWSUB'></ul><sub id='yWSUB'></sub></form><legend id='yWSUB'></legend><bdo id='yWSUB'><pre id='yWSUB'><center id='yWSUB'></center></pre></bdo></b><th id='yWSUB'></th></span></q></dt></tr></i><div id='yWSUB'><tfoot id='yWSUB'></tfoot><dl id='yWSUB'><fieldset id='yWSUB'></fieldset></dl></div>
                  本文介绍了如何从具有特定值的 stl 向量中删除项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在查看 stl vector 的 API 文档,并注意到 vector 类上没有允许删除具有特定值的元素的方法.这似乎是一个常见的操作,而且没有内置的方法来执行此操作似乎很奇怪.

                  I was looking at the API documentation for stl vector, and noticed there was no method on the vector class that allowed the removal of an element with a certain value. This seems like a common operation, and it seems odd that there's no built in way to do this.

                  推荐答案

                  std::remove 实际上并没有从容器中删除元素,但它确实返回了可以传递的新的结束迭代器到 container_type::erase 以真正删除现在位于容器末尾的额外元素:

                  std::remove does not actually erase the element from the container, but it does return the new end iterator which can be passed to container_type::erase to do the REAL removal of the extra elements that are now at the end of the container:

                  std::vector<int> vec;
                  // .. put in some values ..
                  int int_to_remove = n;
                  vec.erase(std::remove(vec.begin(), vec.end(), int_to_remove), vec.end());
                  

                  这篇关于如何从具有特定值的 stl 向量中删除项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is the past-the-end iterator in STL C++?(STL C++ 中的最后迭代器是什么?)
                  vector::at vs. vector::operator[](vector::at 与 vector::operator[])
                  C++ equivalent of StringBuffer/StringBuilder?(C++ 等效于 StringBuffer/StringBuilder?)
                  Adding types to the std namespace(将类型添加到 std 命名空间)
                  Is the C++ std::set thread-safe?(C++ std::set 线程安全吗?)
                  How to use std::find/std::find_if with a vector of custom class objects?(如何将 std::find/std::find_if 与自定义类对象的向量一起使用?)
                  1. <legend id='Ptngu'><style id='Ptngu'><dir id='Ptngu'><q id='Ptngu'></q></dir></style></legend>
                      <tfoot id='Ptngu'></tfoot>
                          <bdo id='Ptngu'></bdo><ul id='Ptngu'></ul>

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

                              <tbody id='Ptngu'></tbody>

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