Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
C++ Program to implement the use of STL Map:
#include<iostream>
#include<map>
// Used to store key value pairs. (Eg: To maintain Phone Book )
using namespace std;
int main()
{
map<string,long long>phonebook;
cout<<"Choice:\n 1) Adding a entry into phone book.\n 2) Query to retrieve the person's number.";
int ch;
long long no;
string s;
while(1){
cout<<"\nEnter your choice...";
cin>>ch;
if(ch==1){
cout<<"\nEnter the name.";
cin>>s;
cout<<"Enter the phone number.";
cin>>no;
phonebook[s]=no;
}
else if(ch==2){
cout<<"\nEnter the name whose number you want to retrieve.";
cin>>s;
cout<<"The phone number is."<<phonebook[s];
}
else{
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.