1

I'm trying to delete a record in my vector STL with iterator. But exception is thrown.

for (it = sp.begin(); it != sp.end(); ++it)
    {
        if (it->Id() == d)
            {
                sp.erase(it); //Where error starts
            }
    }

After I reached these code, It pops out to error exception

_STL_VERIFY(_Ptr < _Mycont->_Mylast, "can't increment vector iterator past end");

Exception thrown: read access violation. _Mycont was nullptr.

Vincent.L
  • 13
  • 3
  • 5
    related https://stackoverflow.com/questions/991335/how-to-erase-delete-pointers-to-objects-stored-in-a-vector basically you're invalidating the iterator once you delete – EdChum Jul 24 '19 at 08:16

0 Answers0