• <small id='5ETD8'></small><noframes id='5ETD8'>

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

      <bdo id='5ETD8'></bdo><ul id='5ETD8'></ul>

    1. <legend id='5ETD8'><style id='5ETD8'><dir id='5ETD8'><q id='5ETD8'></q></dir></style></legend>

        <tfoot id='5ETD8'></tfoot>

        Vector of Vectors 创建矩阵

        时间:2023-09-18
            <tbody id='YwZm0'></tbody>

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

                  本文介绍了Vector of Vectors 创建矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试输入二维矩阵的维度.然后使用用户输入来填充这个矩阵.我尝试这样做的方法是通过向量(向量的向量).但是每当我尝试读取数据并将其附加到矩阵时,我都会遇到一些错误.

                  I am trying to take in an input for the dimensions of a 2D matrix. And then use user input to fill in this matrix. The way I tried doing this is via vectors (vectors of vectors). But I have encountered some errors whenever I try to read in data and append it to the matrix.

                  //cin>>CC; cin>>RR; already done
                  vector<vector<int> > matrix;
                  for(int i = 0; i<RR; i++)
                  {
                      for(int j = 0; j<CC; j++)
                      {
                      cout<<"Enter the number for Matrix 1";
                           cin>>matrix[i][j];
                      }
                  }
                  

                  每当我尝试这样做时,它都会给我一个下标超出范围的错误.有什么建议吗?

                  Whenever I try to do this, it gives me a subscript out of range error. Any advice?

                  推荐答案

                  事实上,向量的两个维度都是 0.

                  As it is, both dimensions of your vector are 0.

                  相反,将向量初始化为:

                  Instead, initialize the vector as this:

                  vector<vector<int> > matrix(RR);
                  for ( int i = 0 ; i < RR ; i++ )
                     matrix[i].resize(CC);
                  

                  这将为您提供一个维度矩阵 RR * CC,其中所有元素都设置为 0.

                  This will give you a matrix of dimensions RR * CC with all elements set to 0.

                  这篇关于Vector of Vectors 创建矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:根据输入动态二维数组 下一篇:在 C++ 中创建矩阵的正确方法

                  相关文章

                  最新文章

                  <small id='6h5LJ'></small><noframes id='6h5LJ'>

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

                    <bdo id='6h5LJ'></bdo><ul id='6h5LJ'></ul>

                  1. <legend id='6h5LJ'><style id='6h5LJ'><dir id='6h5LJ'><q id='6h5LJ'></q></dir></style></legend>