c++ - 在 map 中迭代 map

标签 c++ dictionary loops

我在迭代 map 中的第二张 map 时遇到问题。

#include <map>

using namespace std;

map<string, map<string, string> > mymap;
map<string, map<string, string> >::iterator itm;
pair<map<string, map<string, string> >::iterator,bool> retm;

for( itm=mymap.begin(); itm!=mymap.end(); ++itm)
{
cout << "first:\t" << it->first << endl;
}

如何遍历第二个映射并获取第一个和第二个键/值?

第二个问题是,如何使用 map 自带的“插入”功能“插入”到第一张和第二张 map 中?

我希望有人能给出完整的答案。

最佳答案

it->second 会给你“第二张 map ”。只需迭代即可。

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

相关文章:

c# - x32 和 x64 的公共(public)注册表区域

c++ - ifstreams 的 vector

c++ - C++ 中 <Pointer, String> 的 unordered_map

javascript - PHP MySQL JS AJAX - 循环问题

python - Dask 延迟初始化对于列表理解来说非常慢

c++ - 为什么试图存储指向函数的指针不明确

c++ - 可以同时容纳Foo *和std::shared_ptr <Foo>的类型

python - 在基于颜色聚类的图中绘制节点

xml - 如何解析文件夹中的 XML 文件以映射 String,List<String>

javascript - jQuery Loop by id 为每个元素