title: Access violation C++ (Deleting items in a vector)
body: <p>I'm trying to remove non-matching results from a memory scanner I'm writing in C++ as practice. When the memory is initially scanned, all results are stored into the <code>_results</code> vector.</p>
  
  <p>Later, the <code>_results</code> are scanned again and should erase items that no longer match.</p>
  
  <p><strong>The error:</strong></p>
  
  <blockquote>
    <p>Unhandled exception at 0x004016f4 in
    .exe: 0xC0000005: Access
    violation reading location 0x0090c000.</p>
  </blockquote>
  
  <pre><code>// Receives data
  
  DWORD buffer;
  
  for (vector&lt;memblock&gt;::iterator it = MemoryScanner::_results.begin(); it != MemoryScanner::_results.end(); ++it) {
      // Reads data from an area of memory into buffer
      ReadProcessMemory(MemoryScanner::_hProc, (LPVOID)(*it).address, &amp;buffer, sizeof(buffer), NULL);
  
      if (value != buffer) {
          MemoryScanner::_results.erase(it); // where the program breaks
      }
  }
  </code></pre>