-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.cpp
More file actions
32 lines (28 loc) · 841 Bytes
/
map.cpp
File metadata and controls
32 lines (28 loc) · 841 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
#include<iostream>
#include<map>
using namespace std;
//stored the data in key value pair
int main(){
map<int,string>m;
//1 is key and Ajay is value
m[1]="Ajay";
m[2]="Nanjay";
m[4]="Manjay";
m.insert({5,"antika"});
for(auto i:m){
//expression can not be used as a function
//i.first() dont write this way
cout<<i.first<<" "<<i.second<<" "<<endl;
}
cout<<"find the element "<<m.count(-13)<<endl; //count return 0 or 1(0-->variable doesnot exist)
m.erase(5);
cout<<"after erase"<<endl;
for(auto i:m){
cout<<i.first<<" "<<i.second<<" "<<endl;
}
//find the element from map
auto findElement=m.find(4);
for(auto i=findElement;i!=m.end();i++){
cout<<(*i).first<<" "<<(*i).second<<endl;
}
}