#include<iostream>
#include<map> // for map operations
using
namespace
std;
int
main()
{
map<
char
,
int
> mp;
map<
char
,
int
>::iterator it ;
map<
char
,
int
>::iterator it1;
map<
char
,
int
>::iterator it2;
mp[
'a'
]=5;
mp[
'b'
]=10;
mp[
'c'
]=15;
mp[
'd'
]=20;
mp[
'e'
]=30;
cout <<
"The initial map elements are : \n"
;
for
(it1 = mp.begin(); it1!=mp.end(); ++it1)
cout << it1->first <<
"->"
<< it1->second << endl;
it = mp.begin();
cout << endl;
++it;
mp.erase(it);
cout <<
"The map elements after 1st deletion are : \n"
;
for
(it1 = mp.begin(); it1!=mp.end(); ++it1)
cout << it1->first <<
"->"
<< it1->second << endl;
cout << endl;
int
c = mp.erase(
'c'
);
cout <<
"The map elements after 2nd deletion are : \n"
;
for
(it1 = mp.begin(); it1!=mp.end(); ++it1)
cout << it1->first <<
"->"
<< it1->second << endl;
cout <<
"The number of elements deleted in 2nd deletion are : "
;
cout << c << endl;
cout << endl;
int
d = mp.erase(
'w'
);
cout <<
"The map elements after 3rd deletion are : \n"
;
for
(it1 = mp.begin(); it1!=mp.end(); ++it1)
cout << it1->first <<
"->"
<< it1->second << endl;
cout <<
"The number of elements deleted in 3rd deletion are : "
;
cout << d << endl;
cout << endl;
++it;
++it;
mp.erase(it, mp.end());
cout <<
"The map elements after 4th deletion are : \n"
;
for
(it1 = mp.begin(); it1!=mp.end(); ++it1)
cout << it1->first <<
"->"
<< it1->second << endl;
cout << endl;
}