Advertisement
AbhijitPaul

Map Example

Jul 7th, 2022
619
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   #include<bits/stdc++.h>
  2.   using namespace std;
  3.  
  4.  
  5.   void print_map(map<int, string> m);
  6.   void print_vector(vector<pair<int, string>> m);
  7.  
  8.   int main(){
  9.     map<int,string> test_map;
  10.     test_map.insert({1201, "Abhijit Paul"});
  11.     test_map.insert({1299, "Robin ho"});
  12.     test_map.insert({1203, "Shazzad Hossain"});
  13.  
  14.     for(auto itr: test_map ){
  15.       itr.second = itr.second+" ALIVE";
  16.     }
  17.  
  18.     print_map(test_map); // NO change
  19.  
  20.     printf("After using &:\n");
  21.     for(auto& itr: test_map){
  22.       test_map.erase(itr.first);
  23.       test_map.insert({itr.first-1200, itr.second+" ALIVE"});
  24.     }
  25.  
  26.     print_map(test_map);
  27.  
  28.  
  29.     return 0;
  30.   }
  31.  
  32.  
  33.   void print_map(map<int, string> m){
  34.     for(const auto itr: m) cout<<itr.first<<","<<itr.second<<endl;
  35.   }
  36.   void print_vector(vector<pair<int, string>> m){
  37.     for(const auto itr: m) cout<<itr.first<<","<<itr.second<<endl;
  38.   }
  39.  
  40.  
Advertisement
RAW Paste Data Copied
Advertisement