获取内部 STL 容器的迭代器?
我在尝试获取内部子容器的迭代器时遇到问题。
基本上想象一下这个简化的代码:
typedef map<string, map<string, map> > double_map;
double_map dm;
.. //some code here
for(double_map::iterator it = dm.begin(); it != dm.end(); it++){
//some code here
it->first // string
it->second // <---- this is the 2nd map, how do i get its iterator so I can wrap it
//in a for loop like above?
}
我需要能够在不为每个内部容器使用 typedef 的情况下执行此操作,有没有办法获取内部容器的迭代器?我的结构有 4 个内部容器,我需要遍历它们。
I am having trouble trying to get iterators for inner sub-containers.
Basically imagine this simplified code:
typedef map<string, map<string, map> > double_map;
double_map dm;
.. //some code here
for(double_map::iterator it = dm.begin(); it != dm.end(); it++){
//some code here
it->first // string
it->second // <---- this is the 2nd map, how do i get its iterator so I can wrap it
//in a for loop like above?
}
I need to be able to do this without using typedefs for every single inner container, is there a way to get an iterator for the inner container? I have structure that has 4 inner containers and I need to iterate through them all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(请注意,以下代码片段中没有编译任何内容。)
编辑:我正确理解您的评论,您想要获取内部映射的迭代器的类型。如果是这样,这是一种方法:
在我的脑海中,这也应该有效:
(Beware, nothing compiled in the following snippets.)
Edit: I fI understand your comment correctly, you want to get at the type of the iterators of the inner map. If that is so, here's one way:
Off the top of my head, this should work, too:
简单的:
Simple: