Mega Code Archive
Categories
/
C++ Tutorial
/
Map Multimap
Compare two maps
#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)); // Create another map that is the same as the first. map
m2(m); show("Contents of m2: ", m2); // Compare two maps. if(m == m2) cout << "m and m2 are equivalent.\n\n"; 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; }