-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathg_1_maps.cpp
42 lines (33 loc) · 989 Bytes
/
g_1_maps.cpp
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
//Map :- Map is a (key, value) pair which contain all the unique keys.
#include<bits/stdc++.h>
using namespace std;
int main()
{
//Syntax of Map
//map<key_dataType, value_dataType> variable_name;
//HOW TO DECLARE AND INITIALISE A MAP.
// map<int,string>m;
// m[0] = "Hello";
// m[1] = "My";
// m[2] = "Name";
// m[3] = "is";
// m[4] = "Priyanshu";
// for(auto i: m)
// cout<<i.first<<" -> "<<i.second<<endl;
//find() --> this function is used to find the key present in map
// it returns the iterator.
map<int,string>m;
m[0] = "Hello";
m[1] = "My";
m[2] = "Name";
m[3] = "is";
m[4] = "Priyanshu";
auto i = m.find(5);
if(i != m.end())
cout<<i->second<<endl;
else
cout<<"Key not found"<<endl;
m.erase(3);
for(auto it : m)
cout<<it.first<<" --> "<<it.second<<endl;
}