C++ examples for STL:map
Mapping strings to Other Things, Creating a string map
#include <iostream> #include <map> #include <string> using namespace std; int main() {//from ww w . j ava 2s .c o m map<string, string> strMap; strMap["Monday"] = "M"; strMap["Tuesday"] = "D"; strMap["Wednesday"] = "W"; strMap["Thursday"] = "T"; strMap["Friday"] = "F"; strMap["Saturday"] = "S"; strMap.insert(pair<string, string>("Sunday", "Sun")); for (map<string, string>::iterator p = strMap.begin(); p != strMap.end(); ++p ) { cout << "English: " << p->first << ", German: " << p->second << endl; } cout << endl; strMap.erase(strMap.find("Tuesday")); for (map<string, string>::iterator p = strMap.begin(); p != strMap.end(); ++p ) { cout << "English: " << p->first << ", letter: " << p->second << endl; } }