O'Reilly logo

Using the C++ Standard Template Libraries by Ivor Horton

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

people["Jim"] = 22;                             // Set Jim's age to 22;people["May"] = people["Jim"];                  // Set May's age to Jim's++people["Joe"];                                // Increment Joe's agepeople["Kit"] = people["Joe"];                  // Set Kit's age to Joe's

This works the same as in a map container. Using a key that does not exist with the subscript operator for an element will cause an element with that key to be created with a default value for the associated object. The last statement will create the element with "Kit" as the key and the age as 0 if there is no "Kit" in the container; the object associated with "Joe" will then be copied to "Kit."

The at() member returns a reference to the object associated with ...

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