// 1019.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <map> #include <utility> #include <string> #include <vector> #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { map< string,vector< pair<string,string> > > name_map; string surname,childname,birthday; cout << "Enter the last name for map:"; while ( cin >> surname ) { vector< pair<string,string> > child_vector; pair <map< string,vector< pair<string,string> > >::iterator,bool> ret = name_map.insert(make_pair(surname,child_vector)); if(!ret.second) cout << surname << " has been existed! Add the childname and birthday:" << endl; else cout << "Enter the childname and birthday for " << surname << ":" << endl; while (cin >> childname >> birthday) ret.first->second.push_back( make_pair(childname,birthday) ); cin.clear(); cout << "Enter the last name for map:"; } cin.clear(); cout << "enter the surname to be searched:"; while (cin >> surname) { map< string,vector< pair<string,string> > >::iterator iter = name_map.find(surname); if (iter == name_map.end()) { cout << "surname is not existed,enter again:" << endl; continue; } for (vector< pair<string,string> >::iterator it = iter->second.begin();it != iter->second.end();it++) cout << it->first << " " << it->second << endl; cout << "enter the surname to be searched:"; } return 0; }