iterator assert after inserting in the vector
When I try to use iterator to insert elements in a vector continuously, the iterator becomes invalid and it displays a dialog box at run time. The reason is as following. (see the original)
Debug Iterator Support
The Visual C++ runtime library now detects incorrect iterator use and will assert and display a dialog box at run time. To enable debug iterator support, a program must be compiled with a debug version of a C run time library (see C Run-Time Libraries for more information).
See Checked Iterators for more information on using iterators.
The C++ standard describes which member functions cause iterators to a container to become invalid. Two examples are:
-
Erasing an element from a container causes iterators to the element to become invalid.
-
Increasing the size of a vector (push or insert) causes iterators into the vector container become invalid.