我正在製作一個管理酒店的課程。我能夠成功地將客戶簽入房間。但是,當我嘗試從房間簽出客戶時,我得到一個運行時錯誤:矢量迭代器不兼容。我運行調試器,並說問題出在我的while循環的條件語句中,但我無法弄清楚問題所在(我想我正確使用了調試器)。我試着用這個類似的錯誤看着其他帖子,但我無法找到解決方案。誰能幫忙?一旦erase
操作已被執行獲取錯誤:矢量迭代器不兼容
void Customer::removeRoomID(int rID)
{
vector<int>::iterator iter;
iter = roomsCheckedInto.begin();
while(iter != roomsCheckedInto.end()) // <--DEBUGGER SAYS ERROR IN THIS LINE - ERROR: VECTOR ITERATOR INCOMPATIBLE
{
if(*iter==rID)
{
roomsCheckedInto.erase(iter);
}
}
}
我推薦[Erase-Remove Idiom](http://en.wikipedia.org/wiki/Erase-remove_idiom)。 – 2012-03-22 21:42:27