c++ - 列出 map 变量中的项目

标签 c++ dictionary

我只是想从 map 变量中获取值。但由于某种原因,它给出了一个错误:'std::operator<< 错误中的 'operator<<' 不匹配。这是我的代码片段。

std::map <string, list<int> > gradeList;
....
gradeList.insert(std::make_pair("A", itemVal));

然后我尝试用 for 循环打印它

for(map<string, list<int> >::iterator it = gradeList.begin(); it != gradeList.end(); ++it) {
        cout << it->first << " " << it->second <<  "\n";
    }

这给我错误。知道发生了什么事吗?

谢谢

最佳答案

你得到一个错误,因为 it->second 是一个 std::list,它没有重载输出运算符。

关于c++ - 列出 map 变量中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24965182/

相关文章:

arrays - 如何在Dart中对该数组/映射进行排序?

python - 将文件加载到yaml时如何保持键的插入顺序?

Python从内部函数更改外部字典

dictionary - Swift 中带有命名元组的速记字典

c++:将ostream存储在列表中

c++ - 从类外部调用类方法内的函数,名称与类中的一个方法相同

c++ - 在Windows 7上将原始数据写入硬盘(PhysicalDrive)的最快方法

c++ - 使用各种数据类型的成员创建对象的简单方法

java - 更改图表中的 Java 映射

c++ - 将 C++ 移植到 Python 代码