Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
map::swap()_30-Seconds-of-C++
#include <iostream> #include <map> int main() { // declaration of map containers of same type std::map<char, int> mp1, mp2; mp1['a'] = 1; mp1['b'] = 2; mp1['c'] = 3; mp2['A'] = 5; mp2['B'] = 10; mp2['C'] = 11; std::map<char, int>::iterator itr; std::cout << "Key-Value pair of mp1 before swap: " << std::endl; for(itr = mp1.begin(); itr != mp1.end(); ++itr) std::cout << itr->first << " " << itr->second << std::endl; std::cout << "Key-Value pair of mp2 before swap: " << std::endl; for(itr = mp2.begin(); itr != mp2.end(); ++itr) std::cout << itr->first << " " << itr->second << std::endl; mp1.swap(mp2); std::cout << "Key-Value pair of mp1 after swap: " << std::endl; for(itr = mp1.begin(); itr != mp1.end(); ++itr) std::cout << itr->first << " " << itr->second << std::endl; std::cout << "Key-Value pair of mp2 after swap: " << std::endl; for(itr = mp2.begin(); itr != mp2.end(); ++itr) std::cout << itr->first << " " << itr->second << std::endl; return 0; }
run
|
edit
|
history
|
help
0
543
Polyrmophism
NonparaH
10 wizards
Op&&^Overload
TIME
printAllPathsInMatrix
generate BinTree from sorted list
Primality Test | Fermat
sortbyfrequency(hasing+sorting using comparator function)