Created
August 21, 2016 08:45
-
-
Save ravikiran0606/fe04935e194f4f943b2d357fb14a4e51 to your computer and use it in GitHub Desktop.
C++ Program to implement the use of STL Map:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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