c++ - 在 map : How to clear inner map using iterators? 中映射

标签 c++ stl

我在另一个具有以下结构的 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 集中。在执行插入之前,我想检查给定外部映射键的内部映射的当前键。

  1. 如果当前内部键大于要插入的值,我想清除整个内部映射并只添加这个新值作为新的内部映射键。
  2. 如果当前内键等于要 插入,我会将条目添加到内部 map 的集合中。
  3. 如果当前内键小于传入值,则丢弃传入值。

我能够实现第二个和第三个条件,我需要一些关于第一个条件的帮助。即清除与外部 map 中特定键对应的整个内部 map 。

谢谢。

最佳答案

clear()应该符合您的要求。

关于c++ - 在 map : How to clear inner map using iterators? 中映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36853780/

相关文章:

c++ - 来自 Voronoi 的 Delaunay boost : missing triangle with non-integral point coordinates

C++容器按键和值搜索

c++ - 关于 map STL的问题

c++ - 将 map<>::iterator 作为 map<>::const_iterator &

C++ freeRTOS 任务,非静态成员函数的无效使用

c++ - 如何将文件嵌入到可执行文件中?

c++ - [windows] 反向链接

c++ - 迭代多个 std::vector

c++ - 哪种数据结构或 STL 用于保存具有值的对?

c++ - 用 CString 替换 LPCTSTR 是否安全?