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

    <legend id='01wDh'><style id='01wDh'><dir id='01wDh'><q id='01wDh'></q></dir></style></legend>

      <tfoot id='01wDh'></tfoot>

      <small id='01wDh'></small><noframes id='01wDh'>

        如何一次将多个整数传递给一个向量?

        时间:2023-09-15

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

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

            1. <legend id='vriLH'><style id='vriLH'><dir id='vriLH'><q id='vriLH'></q></dir></style></legend>
                <tbody id='vriLH'></tbody>
            2. <tfoot id='vriLH'></tfoot>

                • <bdo id='vriLH'></bdo><ul id='vriLH'></ul>
                  本文介绍了如何一次将多个整数传递给一个向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  目前当我必须多次使用 vector.push_back() 时.

                  Currently when I have to use vector.push_back() multiple times.

                  我目前使用的代码是

                    std::vector<int> TestVector;
                    TestVector.push_back(2);
                    TestVector.push_back(5);
                    TestVector.push_back(8);
                    TestVector.push_back(11);
                    TestVector.push_back(14);
                  

                  有没有办法只使用 vector.push_back() 一次并且只将多个值传递给向量?

                  Is there a way to only use vector.push_back() once and just pass multiple values into the vector?

                  推荐答案

                  尝试将数组传递给向量:

                  Try pass array to vector:

                  int arr[] = {2,5,8,11,14};
                  std::vector<int> TestVector(arr, arr+5);
                  

                  您可以随时调用 std::vector::assign 将数组分配给向量,调用 std::vector::insert 添加多个数组.

                  You could always call std::vector::assign to assign array to vector, call std::vector::insert to add multiple arrays.

                  如果你使用 C++11,你可以试试:

                  If you use C++11, you can try:

                  std::vector<int> v{2,5,8,11,14};
                  

                   std::vector<int> v = {2,5,8,11,14};
                  

                  这篇关于如何一次将多个整数传递给一个向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在前面插入向量 下一篇:C++ 试图交换向量中的值

                  相关文章

                  最新文章

                  <tfoot id='HBg4s'></tfoot>

                    • <bdo id='HBg4s'></bdo><ul id='HBg4s'></ul>
                    <legend id='HBg4s'><style id='HBg4s'><dir id='HBg4s'><q id='HBg4s'></q></dir></style></legend>
                  1. <small id='HBg4s'></small><noframes id='HBg4s'>

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