Mega Code Archive
Categories
/
C++ Tutorial
/
Map Multimap
Create another map that is the same as the first
#include
#include
#include
using namespace std; void show(const char *msg, map
mp); int main() { map
m; m.insert(pair
("A", 100)); m.insert(pair
("G", 300)); m.insert(pair
("B", 200)); map
::iterator itr; // Create another map that is the same as the first. map
m2(m); show("Contents of m2: ", m2); return 0; } // Display the contents of a map
by using an iterator. void show(const char *msg, map
mp) { map
::iterator itr; cout << msg << endl; for(itr=mp.begin(); itr != mp.end(); ++itr) cout << " " << itr->first << ", " << itr->second << endl; cout << endl; }