[cpp] #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++) { www.2cto.com for(intertr= multitr ->second.begin(); intertr != multitr ->second.end(); intertr ++) cout<< multitr ->first<<" "<<intertr->first<<" ("<<intertr -> second <<")"<<endl; } system("pause"); return 0; }