title: Assigning values to 2D Vector by using indices
body: <p>I am trying to add values to a 2D vector by using both indices. When I run my program, I get the windows message saying the program has stopped working. Using Dev-C++ to debug showed that there was a segmentation fault (I am not sure what this means). Please do not suggest using arrays, I have to use vectors for this assignment.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  int main(int argc, char** argv) { 
  
  vector&lt; vector&lt;int&gt; &gt; matrix;
  cout &lt;&lt; "Filling matrix with test numbers.";
  for (int i = 0; i &lt; 4; i++) {
      for (int j = 0; j &lt; 4; j++) {
  
          matrix[i][j] = 5; // causes program to stop working
  
      }
  }
  }
  </code></pre>
  
  <p>I have created a test case where I want to fill a 3X3 matrix with the value 5. I suspect that it has something to do with the size of the 2D vector not being specifically defined. How would I fill a 2D vector with values by using the indices?</p>