C++断点异常
程序员文章站
2022-04-08 10:42:24
1.如下代码报错 list iterator not incrementable:
for (list::iterator it = pair_list.begin(); i...
1.如下代码报错 list iterator not incrementable:
for (list::iterator it = pair_list.begin(); it != pair_list.end();it++) { Pair p = *it; if ((p.v1 == pv && p.v2 == v2) || (p.v1 == v2 && p.v2 == pv)) { pair_list.erase(itt); } }
解决方案:
for (list::iterator it = pair_list.begin(); it != pair_list.end();) { Pair p = *it; if ((p.v1 == pv && p.v2 == v2) || (p.v1 == v2 && p.v2 == pv)) { pair_list.erase(it); } else ++it; }
2.以上代码又报错rators incompatible:
解决方案:
将pair_list.erase(it);
改为
it = pair_list.erase(it);