title: vector subscript out of range error message
body: <p>I was trying one of the project euler problems, the first one where it asked you to calculate the sum of all the multiples of 3 and 5 below 1000. 
  I attempted it and it shows no errors, however when i run it i get a message box with the error:</p>
  
  <pre><code>Microsoft Visual C++ Debug Library
  
  Debug Assertion Failed!
  
  Program: ...\c++ learning\project euler ex 1\Debug\project euler ex 1.exe
  File: c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\vector
  Line: 932
  
  Expression: vector subscript out of range
  
  For information on how your program can cause an assertion
  failure, see the Visual C++ documentation on asserts.
  
  (Press Retry to debug the application)
  
  Abort   Retry   Ignore   
  </code></pre>
  
  <p>here is the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;numeric&gt;
  
  using std::endl; using std::cout;
  using std::vector;
  
  int main()
  {
  vector&lt;int&gt; five;
  vector&lt;int&gt; three;
  int x;
  int y;
  int sum;
  
  for(int i = 0; i &lt; 1000; i = i + 5)
  {
      five.push_back(i);
  }
  
  for(int i = 0; i &lt; 1000; i = i + 3)
  {
      three.push_back(i);
  }
  
  
  
  for(vector&lt;int&gt;::iterator it = five.begin(); it != five.end(); ++it)
  {
      if (five[*it] % 3 == 0)
      {
          it = five.erase(it);
      }
  }
  
  for(vector&lt;int&gt;::iterator it = three.begin(); it != three.end(); ++it)
  {
      if (three[*it] % 5 == 0)
      {
          it = three.erase(it);
      }
  }
  
  x = accumulate(five.begin(), five.end(), 0);
  cout &lt;&lt; x &lt;&lt; endl;
  
  y = accumulate(three.begin(), three.end(), 0);
  cout &lt;&lt; y &lt;&lt; endl;
  
  sum = x + y;
  cout &lt;&lt; sum &lt;&lt; endl;
  system("PAUSE");
  return 0;
  }
  </code></pre>
  
  <p>I know there is a much easier way to do that problem, however i am still learning c++ and wanted to try and use some of the things i had recently learnt. </p>