c++ - 无法在地图中打印地图中的矢量值
问题描述
我正在尝试打印地图地图的全部内容,但一直遇到问题。这是我的地图初始化map<int, map<int, vector<int>>> myMap;
我尝试了以下代码:
for( auto const & cit : myMap)
{
cout << cit.first << " : ";
auto const & imap = cit.second;
for( auto const & cit2 : imap )
{
cout << cit2.first << ":" << cit2.second << ","; // errors out
//cout << cit2.first << ":"; // works, but it is not printing out the vector<int> portion
}
cout << endl;
}
如上所述,一旦cit2.second
使用,我收到以下错误:
error: no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and 'const std::vector<int>')|
有人可以给我一些见解吗?
解决方案
你需要这样做。
for( auto const & cit : myMap)
{
cout << cit.first << " : ";
auto const & imap = cit.second;
for( auto const & cit2 : imap )
{
cout << cit2.first << ":";
auto const &vec = cit2.second;
for(auto const &i : vec)
{
cout<<i<<" ";
}cout<<endl;
//cout << cit2.first << ":"; // works, but it is not printing out the vector<int> portion
}
cout << endl;
}
推荐阅读
- amazon-web-services - 在 aws cloudsearch 中提取错误的结果
- sql - 在 CASE 语句中的 THEN 之后添加 OR 的方法?
- azure - Azure 前端 Web APP 和 Azure APIM 相互客户端证书身份验证不起作用
- java - spring-data-hazelcast @Query 注释给出 NullPointerException
- swift - 期望 SwiftUI DynamicProperty 属性包装器的内部更新来触发视图更新是否正确?
- javascript - 谷歌脚本:变量总是显示未定义
- c - 如何在c中正确扫描txt文件中的东西
- vue.js - 构建 Vue 微前端应用(带有路由和 vuex 商店)
- angular - 找不到“路径”模块中的错误:错误:无法解析 - Angular 6 Webpack
- php - Facebook - 消息传递 webhook 不断循环回调 php 文件