c++ - std::set 中包含 std::map 的迭代器

标签 c++ dictionary stl set

我怎样才能访问存储在 std::set 中的 map?我需要做类似的事情

for (iterator=map.begin(); iterator!=map.end(); iterator++) {
    some_function(iterator->first);
}

,但不是使用包含 map 的集合来映射 im。

最佳答案

这与迭代任何其他 map 没有太大区别。

set<map<int, int> > s;
for (set<map<int, int> >::iterator it = s.begin(); it != s.end(); ++it) {
  for (map<int, int>::iterator iter = it->begin(); iter != it->end(); ++iter) {
     .. do something ...
  }
}

因此,首先迭代集合,然后迭代外部容器的迭代器指向的 map 元素。我用过map<int, int>这里只是为了说明。

关于c++ - std::set 中包含 std::map 的迭代器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15855247/

相关文章:

c++ - 为什么这两种访问部分 C++ 映射对的方式不同

python - 将列表元素附加到字典

c++ - 将指针容器转换为智能指针?

c++ - 要使用的默认 Visual Studio 项目设置 "rvalueCast"

c++ - ValidateUser 而不是 LogonUser?

c++ - 迭代器模式示例在 C++ 中给出错误

python - 如何检查两个字典的键是否相同

c++ - 如何检查线段是否与任何线相交?

c++ - 在 C++ 中复制类似数据结构的任何模板方式、通用方法?

c++ - 如何设置 QWidget 全屏(但 "real"全屏,更改分辨率,将模态设置为整个系统)?