File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < bits/stdc++.h>
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
+ }
You can’t perform that action at this time.
0 commit comments