我在另一个具有以下结构的 map 中有一个 STL map
typedef set<int> nexthops;
typedef std::map<int, nexthops> innerMap;
typedef std::map<int, innerMap> mainMap;
typedef std::set<int>::const_iterator nexthop_iterator;
typedef map<int, nexthops>::const_iterator innermap_iterator;
typedef map<int, innerMap>::const_iterator outermap_iterator;
我正在尝试将一个值插入到给定外部 map 键的内部 map 集中。在执行插入之前,我想检查给定外部映射键的内部映射的当前键。
- 如果当前内部键大于要插入的值,我想清除整个内部映射并只添加这个新值作为新的内部映射键。
- 如果当前内键等于要 插入,我会将条目添加到内部 map 的集合中。
- 如果当前内键小于传入值,则丢弃传入值。
我能够实现第二个和第三个条件,我需要一些关于第一个条件的帮助。即清除与外部 map 中特定键对应的整个内部 map 。
谢谢。
最佳答案
clear()
应该符合您的要求。
关于c++ - 在 map : How to clear inner map using iterators? 中映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36853780/