A map is a sorted unique associative container that maintains a collection of key value pairs.
These collections are sorted by the key. These collections are unique as only one value is allowed in the collection for the key. Fundamentally, the most frequently used member of the STL's map API is the [] operator. This operator allows convenient access and modification of a key's associated value. If no value for the key specified exists, the key is associated with a default constructor and returns a reference to the new value. If a value is associated to the key specified, a reference to that value is returned. Maps are, therefore, useful for implementing collections of one-to-one mappings.
In the following STL example using STL Map, the Person class has a default c++ constructor that initializes an object of this class to a default null value, which has a blank name, a negative age value and a blank National Insurance Number. The program allows the user to enter some values of Person class into a map that associated the value of the name member to the objects . Then the program allows the user to enter some key values and returns the references to the associated objects.
#include
No comments:
Post a Comment