#include<map> #include<iostream> #include <string> using namespace std; int main() { map<int,map<int,string> >multiMap; //对于这样的map嵌套定义, map<int, string> temp; //定义一个map<int, string>变量,对其定义后在插入multiMap temp[90] = "hi"; temp[100] = "maxi"; multiMap[10] = temp; multiMap[10][80]="xiaoyu"; multiMap[5][30]="xiaoma"; map<int,map<int,string> >::iterator multitr; // 以下是如何遍历本multiMap map<int,string>::iterator intertr; for(multitr=multiMap.begin();multitr!=multiMap.end();multitr++) { for(intertr= multitr ->second.begin(); intertr != multitr ->second.end(); intertr ++) cout<< multitr ->first<<" "<<intertr->first<<" ("<<intertr -> second <<")"<<endl; } system("pause"); return 0; }