O'Reilly logo

Essential C++ by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required