#include <iostream>
#include<map>
using namespace std;
int main() {
map<int,string> m;
m[1]="hi";
m[2]="hello";
m[3]="thanks";
m[4]="namasthe";
for(auto i: m){
cout<<i.first<<" "<<i.second<<"\n";
}
//other way to print map elements
cout<<"\n";
for(auto it=m.begin();it!=m.end();it++){
cout<<(*it).first<<" "<<(*it).second<<"\n";
}
auto itr=m.find(3);
cout<<"\n"<<(*itr).first<<" "<<(*itr).second<<"\n";
m.erase(itr);
cout<<"\n";
for(auto it=m.begin();it!=m.end();it++){
cout<<(*it).first<<" "<<(*it).second<<"\n";
}
m.insert({6,"inserted"});
cout<<"\n";
for(auto it=m.begin();it!=m.end();it++){
cout<<(*it).first<<" "<<(*it).second<<"\n";
}
cout<<"\nSize of map is:"<<m.size()<<"\n";
// m.clear();
// cout<<"\ncleared";
// for(auto it=m.begin();it!=m.end();it++){
// cout<<(*it).first<<" "<<(*it).second<<"\n";
// }
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: