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

posted @ 2016-01-24 21:24  reanote  阅读(419)  评论(0编辑  收藏  举报