1. <tfoot id='SF6SK'></tfoot>

      <bdo id='SF6SK'></bdo><ul id='SF6SK'></ul>

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

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

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

    1. 声明一个二维向量

      时间:2023-09-15

          <tbody id='TqM3J'></tbody>

          <bdo id='TqM3J'></bdo><ul id='TqM3J'></ul>

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

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

                本文介绍了声明一个二维向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                在某些情况下,只有以下行有效.为什么会这样?

                In some cases only the below line works.Why so?

                vector< vector<int>> a(M,N);
                

                这适用于任何情况.

                vector< vector<int>> a(M, vector<int> (N));
                

                有什么区别?

                推荐答案

                std::vector 有一个填充构造函数,它创建一个包含 n 个元素的向量并填充指定的值.a 具有 std::vector> 类型,这意味着它是一个向量的向量.因此,填充向量的默认值是向量本身,而不是 int.因此,第二个选项是正确的.

                std::vector has a fill constructor which creates a vector of n elements and fills with the value specified. a has the type std::vector<std::vector<int>> which means that it is a vector of a vector. Hence your default value to fill the vector is a vector itself, not an int. Therefore the second options is the correct one.

                std::vector>array_2d(rows, std::vector(cols, 0));

                这将创建一个 rows * cols 二维数组,其中每个元素都是 0.默认值是 std::vector(cols, 0) 这意味着每一行都有一个向量,其中 cols 元素个数,每个元素为 0.

                This creates a rows * cols 2D array where each element is 0. The default value is std::vector<int>(cols, 0) which means each row has a vector which has cols number of element, each being 0.

                这篇关于声明一个二维向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:*不*初始化其成员的C++向量? 下一篇:在 C++ 中检查是否 std::vector<string>包含一定的

                相关文章

                最新文章

                <legend id='S5yDm'><style id='S5yDm'><dir id='S5yDm'><q id='S5yDm'></q></dir></style></legend>
              • <small id='S5yDm'></small><noframes id='S5yDm'>

                  <bdo id='S5yDm'></bdo><ul id='S5yDm'></ul>

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