title: How to solve 'vector subscript out of range' error?
body: <p>I'm trying to learn about neural networks using C++, and found a tutorial about digit recognition, but when I run the code I get an error that say "debug assertion failed, vector subscript out of range." Apparently the problem is in the <code>loadTraining</code> function, but don't know how to modify it to eliminate the error.</p>
  
  <pre><code>void loadTraining(const char *filename, vector&lt;vector&lt;double&gt;&gt; &amp;input, vector&lt;vector&lt;double&gt;&gt; &amp;output) 
  {
      int trainingSize = 946;
      input.resize(trainingSize);
      output.resize(trainingSize);
  
      ifstream file(filename);
      if(file) 
      {
          string line;
          int n;
          for (int i=0 ; i&lt;trainingSize ; i++) // load 946 examples
          {
              for (int h=0 ; h&lt;32 ; h++) // 'images' are 32*32 pixels
              {
                  getline(file, line);
                  for (int w=0 ; w&lt;32 ; w++)
                  {
                      input[i].push_back(atoi(line.substr(w,1).c_str()));
                  }
              }
              getline(file, line);
              output[i].resize(10); // output is a vector of size 10
              n = atoi(line.substr(0,1).c_str());
              output[i][n] = 1; // set index that represent the number to 1, other are automatically 0 because of the resize()
          }
      }
      file.close();
  }
  </code></pre>
  
  <p>The file consist of 32*32 arrays of binary digits.
  <a href="https://i.stack.imgur.com/08T4o.png" rel="nofollow noreferrer">This is one training exmple.</a></p>
  
  <p>I'm using visual studio 2013.</p>