-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapintro.cpp
More file actions
70 lines (47 loc) · 1 KB
/
Copy pathmapintro.cpp
File metadata and controls
70 lines (47 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<bits/stdc++.h>
using namespace std;
int main()
{
//Creation
unordered_map<string,int> m;
//Insertion
//1
pair<string,int>p=make_pair("anvi",2);
m.insert(p);
//2
pair<string,int> pair2("haras",2);
m.insert(pair2);
//3
//Creation
m["love"]=1;
//What will happen?
//Upadtion
m["love"]=3;
//search
cout<<m["love"]<<endl;
//cout<<m.at("UnknownKey")<<endl;
cout<<m["UnknownKey"]<<endl;
// and now if we try to print the unknowKey with at
//Because the key is created
cout<<m.at("UnknownKey")<<endl;
//size
cout<< m.size()<<endl;
//Chcek presence of Key
cout<<m.count("love")<<endl;
//erase
m.erase("love");
cout<< m.size()<<endl;
//Print
for(auto i:m)
{
cout<<i.first<<' '<<i.second<<endl;
}
//Iterator
unordered_map<string,int> :: iterator it =m.begin();
while(it!=m.end())
{
cout<<it->first<<" "<<it->second<<endl;
it++;
}
return 0;
}