Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your global definitions of <code>row</code>,<code>col</code>,<code>matrix</code>, ... is the problem. </p> <pre><code>int row=0, col=0; vector&lt;vector&lt;int&gt; &gt; matrix(row, vector&lt;int&gt; (col) ); vector&lt;vector&lt;int&gt; &gt; matrix2(row, vector&lt;int&gt; (col) ); vector&lt;vector&lt;int&gt; &gt; matrix3(row, vector&lt;int&gt; (col) ); </code></pre> <p>What's happening here is the following: <code>row</code> and <code>col</code> is now <code>0</code> and therefore all your matrices now have 0 rows and columns.</p> <p>You can fix this by using the <code>vector::resize()</code> function after you get <code>row</code> and <code>col</code> from the user.</p> <pre><code>cout&lt;&lt;"Enter the number of rows for each Matrix: "&lt;&lt;endl; cin&gt;&gt;row; cout&lt;&lt;"Enter the number of columns for each Matrix: "&lt;&lt;endl; cin&gt;&gt;col; // Resize "matrix" matrix.resize(row); for(int i = 0; i &lt; row; ++i) matrix[i].resize(col); // Repeat for "matrix2" and "matrix3" </code></pre> <p>Also, this means you don't have to "initialize" your <code>matrix</code> objects. So now you can just define them as:</p> <pre><code>vector&lt;vector&lt;int&gt; &gt; matrix; vector&lt;vector&lt;int&gt; &gt; matrix2; vector&lt;vector&lt;int&gt; &gt; matrix3; </code></pre> <h3>Note:</h3> <ol> <li>Think about using <a href="http://www.cplusplus.com/doc/tutorial/other_data_types/" rel="nofollow noreferrer"><code>typedef</code></a> to make your code look better.</li> <li>You don't need them to be global variables. You are using a <code>vector</code> and your <code>printMatrix</code> and <code>addMatrix</code> functions can call <code>vector::size()</code> to find out the size of your matrix. You should rewrite those functions to take your matrix as an argument (lots of good advice <a href="https://stackoverflow.com/questions/2139224/how-to-pass-objects-to-functions-in-c">here</a> on that) and then work on them.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload