| 3 | using namespace std; |
| 4 | |
| 5 | int main() |
| 6 | { |
| 7 | //key,value pairs like dictionary in python |
| 8 | map<int,int>mp; |
| 9 | mp.insert(pair<int,int>(2,20)); |
| 10 | mp.insert(pair<int,int>(3,10)); |
| 11 | |
| 12 | //mp[key]=value |
| 13 | mp[4]=80; |
| 14 | |
| 15 | cout<<mp.size()<<endl; |
| 16 | |
| 17 | for (auto it=mp.begin();it!=mp.end();it++) |
| 18 | { |
| 19 | cout<<it->first<<" "<<it->second<<endl; |
| 20 | } |
| 21 | |
| 22 | //print value of any particular key in key value pair |
| 23 | cout<<mp[3]<<endl; |
| 24 | |
| 25 | //to delete one key value pair enter the key name of the pair |
| 26 | mp.erase(2); |
| 27 | cout<<mp.size()<<endl; |
| 28 | |
| 29 | mp.clear(); |
| 30 | if(mp.empty()) |
| 31 | { |
| 32 | cout<<"Yes"<<endl; |
| 33 | } |
| 34 | else |
| 35 | { |
| 36 | cout<<"No"<<endl; |
| 37 | } |
| 38 | |
| 39 | return 0; |
| 40 | } |