-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapintro.cpp
More file actions
54 lines (38 loc) · 932 Bytes
/
Copy pathmapintro.cpp
File metadata and controls
54 lines (38 loc) · 932 Bytes
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
#include<iostream>
#include<map>
#include<unordered_map>
using namespace std;
int main(){
// creation
unordered_map<string, int> m;
//insertion 1
pair<string,int> p = make_pair("babbar", 3);
m.insert(p);
// insert2
pair<string , int> pair2("love", 2);
m.insert(pair2);
// 3 single entry no duplicate key
m["mera"]=1;
// what will happen
m["mera"]=2;
// search
cout<<m["mera"]<<endl;
cout<<m.at("babbar")<<endl;
cout<<m.at("unknownkey")<<endl;
// size()
cout<<m.size()<<endl;
// check pressence
cout<<m.count("bro")<<endl;
//erase
m.erase("love");
cout<<m.size()<<endl;
// for(auto i: m){
// cout<< i.first<<" "<<i.second<<endl;
// iterator upar nicha ata hai output
unordered_map<string, int>:: iterator it=m.begin();
while(it!=m.end()){
cout<<it->first<<" "<<it->second<<endl;
it++;
}
}
}