// Basic use of STL vector #include #include #include using namespace std; // Print a map template void mapPrint(map myMap, char *mapName){ typename map::iterator i; cout << "Entries of " << mapName << ":" << endl; for (i=myMap.begin(); i!=myMap.end(); i++) cout << "\t" << i->first << "==>" << i->second << endl; } int main(){ map gradeList; map::iterator i; gradeList["John"] = 'B'; gradeList["Mary"] = 'A'; gradeList["Jacobi"] = 'C'; gradeList["Helen"] = 'D'; cout << "gradeList[\"Mary\"] = " << gradeList["Mary"] << endl; cout << "gradeList.size() = " << gradeList.size() << endl; mapPrint(gradeList, "gradeList"); gradeList.erase("Mary"); // Delete "Mary"! cout << "gradeList.size() = " << gradeList.size() << endl; mapPrint(gradeList, "gradeList"); cout << "gradeList[\"Mary\"] = " << gradeList["Mary"] << endl; // Why? cout << "gradeList.size() = " << gradeList.size() << endl; // Why? mapPrint(gradeList, "gradeList"); i=gradeList.find("Jacobi"); if(i==gradeList.end()) cout << "Jacobi is not in the map!" << endl; else cout << i->first << " ==> " << i->second << endl; return 0; }