List的遍历——list iterator not incrementable

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了List的遍历——list iterator not incrementable相关的知识,希望对你有一定的参考价值。

 1 for ( std::list<Type>::iterator it =ObjList.begin(); it != ObjList.end(); )
 2 {
 3        if((*it->regin == CheckRegin )
 4        {
 5               it= ObjList.earse(it);
 6               continue;
 7        }
 8 
 9        else
10       {
11               ++it;
12       }
13 }

List在erase后原来的遍历器就失效了,不能再往下执行,需要continue跳出本次循环。earse操作会返回一个指向container下一个元素的iterator,如果想继续遍历,就得用返回的iterator继续操作。

以上是关于List的遍历——list iterator not incrementable的主要内容,如果未能解决你的问题,请参考以下文章