Question: define a map object. The key of the element is the family name, and the value is the vector object that stores the family name. Enter at least six entries for the map container. Check your program by querying based on the family name. The query should output the names of all the children in the family.
// Define a map object. The key of the element is the family name. // The value is the vector object that stores the family name. // You can query the family name based on the family name, output the names of all children in the family # include <iostream> # include <map> # include <vector> # include <string> using namespace std; int main () {map <string, vector <string> children; string surname, childName; // read the entry (family name and all children's names) do {cout <"Enter surname:" <endl; cin> surname; if (! Cin) // read and end break; // Insert a new entry vector <string> chd; pair <map <string, vector <string >:: iterator, bool> ret = children. insert (make_pair (surname, chd); if (! Ret. second) {// This family name already exists in the map container cout <"repeated surname:" <surname <endl; continue ;} cout <"Enter children's name:" <endl; while (cin> childName) // read the names of all children in the family, ret. first-> second. push_back (childName); cin. clear (); // make the input stream valid again} while (cin); cin. clear (); // make the input stream valid again // read the cout family to be queried <"Enter a surname to search:" <endl; cin> surname; // search for map <string, vector <string> >:: iterator iter = children. Find (surname); // output the query result if (iter = children. end () // unable to find the family name cout <"no this surname:" <surname <endl; else {cout <"children:" <endl; // output the names of all children in the family. vector <string >:: iterator it = iter-> second. begin (); while (it! = Iter-> second. end () cout <* it ++ <endl;} return 0 ;}