map删除迭代器的处理

简介: map删除迭代器的处理

删除部分:

std::map<inti,int> targets;
for(auto it = targets.begin(); it!=targets.end();)
{
    if(......)
    {
        targets.erase(it++);
    }
    else
    {
    it++;
    }
}

全部删除:

std::map<inti,int> targets;
for(auto it = targets.begin(); it!=targets.end();)
{
  it = targets.erase(it);
}
相关文章
|
25天前
Collection和Map的遍历方式
Collection和Map的遍历方式
10 0
|
3天前
|
开发者
迭代器(Iterator)遍历的两种方法(for和while)
迭代器(Iterator)遍历的两种方法(for和while)
|
3天前
list转迭代器Iterator
list转迭代器Iterator
|
4月前
|
C++
c++ unordered_map4种遍历方式
c++ unordered_map4种遍历方式
44 0
|
10月前
List,Map 三种遍历方式:(总结理解)
List,Map 三种遍历方式:(总结理解)
43 0
|
10月前
遍历 ArrayList和遍历 Map的几种方式
遍历 ArrayList和遍历 Map的几种方式
45 0
|
编译器
遍历Map的六种方式
遍历Map的六种方式
142 0
遍历Map的六种方式
|
Java 容器
使用Iterator遍历map以及list用法
使用Iterator遍历map以及list用法
141 0
使用Iterator遍历map以及list用法
【Groovy】map 集合 ( map 集合遍历 | 使用 map 集合的 find 方法遍历 map 集合 | 代码示例 )
【Groovy】map 集合 ( map 集合遍历 | 使用 map 集合的 find 方法遍历 map 集合 | 代码示例 )
343 0
【Groovy】map 集合 ( map 集合遍历 | 使用 map 集合的 find 方法遍历 map 集合 | 代码示例 )