Mega Code Archive
Categories
/
C++
/
Map Multimap
Use string as the key and value in a map
#include
#include
#include
using namespace std; int main() { map
directory; directory.insert(pair
("T", "555-4444")); directory.insert(pair
("C", "555-3333")); directory.insert(pair
("J", "555-2222")); directory.insert(pair
("R", "555-1111")); string s = "T"; map
::iterator p; p = directory.find(s); if(p != directory.end()) cout << "Phone number: " << p->second; else cout << "Name not in directory.\n"; return 0; } /* Phone number: 555-4444 */