Advertisement
arfin97

Referance - Map

Feb 17th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. //http://stackoverflow.com/questions/21815462/enter-standard-input-for-values-of-map
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. int main(){
  7.     map<int, string> name_map;
  8.  
  9.     name_map[1] = "Tom";
  10.     name_map[2] = "Max";
  11.     name_map[3] = "Mark";
  12.     name_map[4] = "John";
  13.     name_map[5] = "Patrik";
  14.  
  15.     name_map.insert(pair<int, string>(6, "Jauly"));
  16.     name_map.insert(pair<int, string>(7, "Jack"));
  17.  
  18.     cout << "is empty?: " << name_map.empty() << endl;
  19.     cout << "map size: " << name_map.size() << endl;
  20.  
  21.     map<int, string>::iterator it = name_map.find(5);
  22.     cout << "key found = " << it->second << endl;
  23.  
  24.     name_map.erase(it);
  25.  
  26.     for(map<int, string>::iterator it = name_map.begin(); it != name_map.end(); it++){
  27.         cout << it->first << " => " << it->second << endl;
  28.     }
  29.  
  30.     name_map.clear();
  31.  
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement