Exercise 3.3
Define a map for which the index is the family surname and the key is a vector of the children’s names. Populate the map with at least six entries. Test it by supporting user queries based on a surname and printing all the map entries.
The map uses a string as an index and a vector of strings for the children’s names. This is declared as follows:
map< string, vector<string> > families;
To simplify the declaration of the map, I’ve defined a typedef to alias vstring as an alternative name for a vector that contains string elements. (You likely wouldn’t have thought of this because the typedef mechanism is not introduced until Section 4.6. The typedef mechanism allows us to provide an alternative name for a type. It is generally ...
Get Essential C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.