0
点赞
收藏
分享

微信扫一扫

c++debug错误 Expression: map/set iterator not incrementable

kiliwalk 2022-09-19 阅读 55


刷题在devC上直接崩死,用vs打断点结果报错 Expression: map/set iterator not incrementable

c++debug错误 Expression: map/set iterator not incrementable_数组

代码如下:

map<string, Record>::iterator it;
for (it = parted.begin();it != parted.end();it++) {
string id = it->second.plateNum;
bool flag = false;
for (int i = lastIndex;i<N;i++) {
if (rec[i].plateNum == id) {
if (rec[i].statue == "in") break;
else {//下面有紧挨着的out与之配对
flag = true;
break;
}
}
}

if (flag == false) {
parted.erase(id);//配对失败的丢掉 循环过程中删除了map 那么it++会报错
}
}

原因在于遍历map的同时在循环体内修改了map,此处删除了map中的键值对,于是迭代器便乱了.it++的指向非法了

c++debug错误 Expression: map/set iterator not incrementable_迭代器_02

此处用string数组把该删的key记录下来,遍历完再删即可解决

举报

相关推荐

C++ map和set

【C++ map和set】

C++容器 - set & map

C++《set与map》

C++容器-list、set、map

【C++】map和set详解

C++set与map容器

0 条评论