C++ 如何在矢量中打印地图的元素?

C++ 如何在矢量中打印地图的元素?,c++,C++,我想打印向量内地图中的值和键 我搜索了如何在Interent上打印地图中的元素,但没有找到结果。如何做到这一点 下面是我的代码 #include <iostream> #include <string> #include <map> using namespace std; vector<map<string,int>> list; vector<map<string, int>>::iterator it;

我想打印向量内地图中的值和键

我搜索了如何在Interent上打印地图中的元素,但没有找到结果。如何做到这一点

下面是我的代码

#include <iostream>
#include <string>
#include <map>

using namespace std;
vector<map<string,int>> list;
vector<map<string, int>>::iterator it;

int N;
int M;

int main(void) {
    cin >> N;

    string s;
    int num = 0;

    for (int i = 0; i < N; ++i) {
        scanf("%s,%d", s, &num);
        map<string, int> product;
        product.insert(pair<string, int>(s, num));
        list.push_back(product);
    }

    for (it = list.begin(); it != list.end(); ++it) {
        //I don't know how to print the elements in the map.
    }
}
#包括
#包括
#包括
使用名称空间std;
向量表;
向量::迭代器;
int N;
int M;
内部主(空){
cin>>N;
字符串s;
int num=0;
对于(int i=0;i
*它将包含您的映射,所以也要循环那些迭代器

 for (it = list.begin(); it != list.end(); ++it) {
    for (map<string, int>::iterator mapIt(it->begin()); mapIt != it->end(); ++mapIt) {

      // output here
      std::cout << mapIt->first << ", " << mapIt->second << std::endl;
    }
}
for(it=list.begin();it!=list.end();++it){
对于(映射::迭代器mapIt(它->开始());mapIt!=它->结束();++mapIt){
//此处输出

std::cout first向量的相关性是什么?如果你不知道如何打印地图的元素,那么它是否在向量中并不重要。