c++ - 遍历 C++ map<int, list<int>>

标签 c++ map iterator

我在尝试遍历 map 及其列表成员时遇到此错误:

error: 'template<class _Category, class _Tp, class _Distance, class _Pointer, class _Reference> struct std::iterator' used without template parameters
invalid use of qualified-name '<declaration error>::ii'
error: 'ii' was not declared in this scope
error: 'struct std::_Rb_tree_iterator<std::pair<const int, std::list<int, std::allocator<int> > > >' has no member named 'second'
error: 'struct std::_Rb_tree_iterator<std::pair<const int, std::list<int, std::allocator<int> > > >' has no member named 'second'

这是代码(之前正确填充了 map ):

map<int, list<int> >::iterator it; 
list<int>iterator:: ii;

for(it=this->mapName.begin(); it!=this->mapName.end(); ++it){ 

    cout<<(*it).first<<" { ";
    for(ii = (*it).second().begin(); ii!=(*it).second.end(); ++ii){
        cout<<(*ii)<<" ";
    }
    cout << " }" << endl;                   
}

有什么建议吗?

最佳答案

这里有一个语法错误:

 list<int>iterator::

应该是

 list<int>::iterator

此外,

(*it).second().begin()

应该是

(*it).second.begin()

关于c++ - 遍历 C++ map<int, list<int>>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10720359/

相关文章:

c++ - C++ 标准是否要求 C 链接函数为 `noexcept` ?

c++ - 如何使用 SDL 一次处理多个按键?

java - 安全转换为 HashMap

python - 如何使用带有 *args 的映射在 python 函数调用中解包元组

c++ - 使用 boost::iterator

c++ - 为什么三元运算符会阻止返回值优化?

c++ - 没有智能指针怎么处理指针?

android - 控制 OverlayItem 大小

c# - 迭代变量如何只读?

php - 为没有容器数组的 ArrayAccess 实现 Iterator 接口(interface)