A map is an indexed data structure, similar to a vector or a deque. However, a map differs from a vector or deque in two important respects:
First, in a map the index values or key values need not be int, but can be any ordered datatype. For example, a map can be indexed by real numbers, or by strings. Any datatype for which a comparison operator can be defined can be used as a key. As with a vector or deque, elements can be accessed through the subscript operator or other techniques.
Second, a map is an ordered data structure. This means that elements are maintained in sequence, the ordering determined by key values. Because maps maintain values in order, they can very rapidly find the element specified by any given key. Searching is performed in logarithmic time. Like a list, maps are not limited in size, but expand or contract as necessary as new elements are added or removed. In large part, a map can simply be considered a set that maintains a collection of pairs.
In other programming languages, a map-like data structure is sometimes referred to as a dictionary, a table, or an associative array. In the C++ Standard Library, there are two varieties of maps:
The map data structure demands unique keys; that is, there is a one-to-one association between key elements and their corresponding values. In a map, the insertion of a new value that uses an existing key is ignored.
The multimap permits multiple different entries to be indexed by the same key.
Both data structures provide relatively fast insertion, deletion, and access operations in logarithmic time.
Whenever you use a map or a multimap, you must include the map header file.