Multimap

#include<iostream>
#include<map>
using namespace std;

int main() {

	/* Declare multimap */
	multimap <string, string> contact;

	/* Multimap iterator */
	multimap <string, string> :: iterator p;

	/* Insert data */
	contact.insert(pair<string, string>("Jonh", "5500-1100-1212"));
	contact.insert(pair<string, string>("Sam", "1222-5555-6666"));
	contact.insert(pair<string, string>("Jonh", "4441-4545-6565"));
	contact.insert(pair<string, string>("James", "6532-5544-8787"));
	contact.insert(pair<string, string>("Ram", "9475-987-2465"));

	string srch = "Jonh";

	/* Search data */
	p = contact.find(srch);
	if(p != contact.end())
		cout << "Contact no of " << srch << " is " << p->second << endl;
	else
		cout << "Contact not found!" << endl;

	/* Erase data */
	contact.erase("Jonh");
	cout << "Contact Deleted!" << endl;

	/* Display all elements */
	for (p = contact.begin(); p != contact.end(); p++) 
		cout << "Name: " << p->first << "\t"<< "Phone No: " << p->second << endl;

	return 0;
}


/* Output */
Contact no of Jonh is 5500-1100-1212
Contact Deleted!
Name: James Phone No: 6532-5544-8787
Name: Ram Phone No: 9475-987-2465
Name: Sam Phone No: 1222-5555-6666

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!