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

Get Using the C++ Standard Template Libraries 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.