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

  • <small id='NLA1h'></small><noframes id='NLA1h'>

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

    <tfoot id='NLA1h'></tfoot>

      <legend id='NLA1h'><style id='NLA1h'><dir id='NLA1h'><q id='NLA1h'></q></dir></style></legend>
      1. 在 C++ 中切片向量

        时间:2023-09-15
      2. <i id='NVQiC'><tr id='NVQiC'><dt id='NVQiC'><q id='NVQiC'><span id='NVQiC'><b id='NVQiC'><form id='NVQiC'><ins id='NVQiC'></ins><ul id='NVQiC'></ul><sub id='NVQiC'></sub></form><legend id='NVQiC'></legend><bdo id='NVQiC'><pre id='NVQiC'><center id='NVQiC'></center></pre></bdo></b><th id='NVQiC'></th></span></q></dt></tr></i><div id='NVQiC'><tfoot id='NVQiC'></tfoot><dl id='NVQiC'><fieldset id='NVQiC'></fieldset></dl></div>

              <tbody id='NVQiC'></tbody>

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

              <tfoot id='NVQiC'></tfoot>
                <bdo id='NVQiC'></bdo><ul id='NVQiC'></ul>
                  <legend id='NVQiC'><style id='NVQiC'><dir id='NVQiC'><q id='NVQiC'></q></dir></style></legend>
                • 本文介绍了在 C++ 中切片向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在 C++ 中,是否有等效的列表切片 [1:] 来自 Python 的向量?我只想从向量中获取除第一个元素之外的所有元素.

                  Is there an equivalent of list slicing [1:] from Python in C++ with vectors? I simply want to get all but the first element from a vector.

                  Python 的列表切片操作符:

                  Python's list slicing operator:

                  list1 = [1, 2, 3]
                  list2 = list1[1:]  
                  
                  print(list2) # [2, 3]
                  

                  C++ 期望的结果:

                  std::vector<int> v1 = {1, 2, 3};
                  std::vector<int> v2;
                  v2 = v1[1:];
                  
                  std::cout << v2 << std::endl;  //{2, 3}
                  

                  推荐答案

                  这可以使用 std::vector 的复制构造函数轻松完成:

                  This can easily be done using std::vector's copy constructor:

                  v2 = std::vector<int>(v1.begin() + 1, v1.end());
                  

                  正如@AlessandroFlati 建议的那样,我应该澄清这将包括 v1.end()

                  As @AlessandroFlati suggested I should clarify that this will include v1.end()

                  这篇关于在 C++ 中切片向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:shrink_to_fit 是将 `std::vector` 的容量减少到其大小的 下一篇:转换向量&lt;int&gt;串起来

                  相关文章

                  最新文章

                  <tfoot id='ddeFx'></tfoot>
                    1. <legend id='ddeFx'><style id='ddeFx'><dir id='ddeFx'><q id='ddeFx'></q></dir></style></legend>

                    2. <small id='ddeFx'></small><noframes id='ddeFx'>

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