When using vectors in the STL,
1, traverse the data and at the same time to modify the case, slightly inattentive, will appear "Vector iterators incompatible!".
For example, the following code:
vector<int> list; for (vector<int>::iterator it = List.begin (); it! = List.end (); ++it) {if1 ) list.erase (it);}
If it is in the final position and performs a erase operation, the assertion occurs when compared to end () because it is not updated.
The correct method should be as follows:
vector<int> list; for (vector<int>::iterator it = List.begin (); it! = list.end ();) { if1) = List.erase (it); Else ++it;}
After all container classes in the STL have performed the erase operation, a iterator is returned, pointing to the successor of the currently deleted element, or end ().
Therefore, after the delete operation is performed, the value returned by the application modifies the iteration element.
2, the empty vector cannot perform the begin operation, otherwise "vector iterators incompatible!" will also appear.
Note points for using vectors