O'Reilly logo

Beginning C++ Programming by Richard Grimes

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

Maps and multimaps

A map container stores two different items, a key and a value, and it maintains the items in an sort order according to the key. A sorted map means that it is quick to locate an item. The class has the same interface as other containers to add items: you can put them into the container via the constructor, or you can use member methods insert and emplace. You also have access to items via iterators. Of course, an iterator gives access to a single value, so with a map this will be to a pair object that has both the key and the value:

    map<string, int> people;     people.emplace("Washington", 1789);     people.emplace("Adams", 1797);     people.emplace("Jefferson", 1801);     people.emplace("Madison", 1809);  people.emplace("Monroe", ...

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