• <tfoot id='DMhRn'></tfoot>
      1. <small id='DMhRn'></small><noframes id='DMhRn'>

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

      4. 获取 STL 向量中大于某个值的元素的所有位置

        Get all positions of elements in STL vector that are greater than a value(获取 STL 向量中大于某个值的元素的所有位置)

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

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

          <legend id='4hx76'><style id='4hx76'><dir id='4hx76'><q id='4hx76'></q></dir></style></legend>

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

              • <bdo id='4hx76'></bdo><ul id='4hx76'></ul>
                  本文介绍了获取 STL 向量中大于某个值的元素的所有位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想知道如何找到验证特定条件(例如大于)的元素的索引位置.例如,如果我有一个 int 值向量

                  vectorⅤ;

                  V 包含值 3 2 5 8 2 1 10 4 7

                  并且我想获取大于 5 的元素的所有 索引位置.我知道 std::find_if 但根据文档,它只找到满足条件的第一个元素.

                  解决方案

                  Loop std::find_if,从上次停止的地方开始.

                  示例(查看效果):

                  std::vector结果;auto it = std::find_if(std::begin(v), std::end(v), [](int i){return i > 5;});而(它!= std::end(v)){results.emplace_back(std::distance(std::begin(v), it));it = std::find_if(std::next(it), std::end(v), [](int i){return i > 5;});}

                  首先我们用第一个结果设置迭代器.如果没有找到,while 循环永远不会执行.否则,存储索引位置(std::distance 基本上是一个更通用的it - std::begin(v)),然后继续搜索.>

                  I would like to know how can I find the index positions of elements that verify a certain condition (for example greater than). For example if I have a vector of int values

                  vector<int> V;
                  

                  V contains the values 3 2 5 8 2 1 10 4 7

                  and I want to get all the index positions of elements that are greater than 5. I know std::find_if but according to the documentation it just finds the first element that satisfies a condition.

                  解决方案

                  Loop std::find_if, starting from where you stopped last time.

                  Sample (see it work):

                  std::vector<size_t> results;
                  
                  auto it = std::find_if(std::begin(v), std::end(v), [](int i){return i > 5;});
                  while (it != std::end(v)) {
                     results.emplace_back(std::distance(std::begin(v), it));
                     it = std::find_if(std::next(it), std::end(v), [](int i){return i > 5;});
                  }
                  

                  First we set up the iterator with the first result. If it's not found, the while loop never executes. Otherwise, the index position is stored (std::distance is basically a more generic it - std::begin(v)), and the search continues onward.

                  这篇关于获取 STL 向量中大于某个值的元素的所有位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Is 1.0 a valid output from std::generate_canonical?(1.0 是 std::generate_canonical 的有效输出吗?)
                  Does std::mt19937 require warmup?(std::mt19937 需要预热吗?)
                  Can I make a thread-safe std::atomiclt;vectorlt;intgt;gt;?(我可以创建一个线程安全的 std::atomicvectorint 吗?)
                  Sort a vector of pairs by first element then by second element of the pair in C++?(在 C++ 中,按第一个元素然后按第二个元素对成对向量进行排序?)
                  vector lt;templategt;, c++, class, adding to vector(vector lt;templategt;, c++, class, add to vector)
                  How does one store a vectorlt;boolgt; or a bitset into a file, but bit-wise?(如何存储向量lt;boolgt;或一个位集到文件中,但按位?)

                      <legend id='dPLUw'><style id='dPLUw'><dir id='dPLUw'><q id='dPLUw'></q></dir></style></legend>

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

                              <tbody id='dPLUw'></tbody>