-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path009map.cpp
More file actions
37 lines (32 loc) · 1.01 KB
/
009map.cpp
File metadata and controls
37 lines (32 loc) · 1.01 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
#include<iostream>
#include<map>
using namespace std;
// map will order thereself as order of available key
int main(){
map<int , string> m;
// insertion
m[2] ="Ashish";
m[15]="Anil";
m[1]="waykar";
for (auto i : m ){
cout<< "Key : "<<i.first<<" value : "<< i.second<<" "<< endl;
} cout<<endl;
cout <<"Inserting the element with another way"<<endl ;
//another way to insert the element in map
m.insert({5," SGGS "});
for(auto i : m ){
cout<<"Key : "<<i.first<<" Value : "<<i.second<<endl;
}
cout<< "finding - 13 -> "<<m.count(-15)<<endl;
cout<< "finding 13 -> "<<m.count(15)<<endl;
// erasing the element (key , value by referance of key )
m.erase(15);
cout<<"after erase : "<<endl;
for (auto i: m){
cout<<" First ELement : "<<i.first<< " Second Element : "<<i.second<<endl;
}
auto it = m.find(5);
for (auto i = it ;i!=m.end();it++){
cout<<(*it).first<<endl;
}
}