Http://blog.csdn.net/feimashenhua/article/details/6654995
Containers in STL are divided into two types by storage method: containers stored in arrays (such as vector and deque), and containers stored in discontinuous nodes (such: list, set, map ). When using the erase method to delete elements, pay attention to some issues to avoid unexpected errors or crashes.
You can use this function when using list, set, or map traversal to delete certain elements.
STD: List <int> list;
STD: List <int >:: iterator itlist;
For (itlist = List. Begin (); itlist! = List. End ();)
{
If (Find(* Itlist ))
{
List. Erase (itlist ++ );
}
Else
Itlist ++;
}
when using vector and deque to traverse and delete elements, you can also use the erase return value to obtain the location of the next element:
STD: vector VEC;
STD: vector : iterator itvec;
for (itvec = Vec. begin (); itvec! = Vec. end ();)
{< br> If (find (* itvec)
{< br> itvec = Vec. erase (itvec);
}< br> else
itlist ++;
}