C++迭代器中删除元素
C++迭代器中删除元素的方式
vector<Player>::iterator it=allPlayers.begin() for (; it!=allPlayers.end(); /*it++*/) <----------- I commented it. { if(it->getpMoney()<=0) { it = allPlayers.erase(it); } else { ++it; } }
From: http://stackoverflow.com/questions/8628951/remove-elements-of-a-vector-inside-the-loop