C++ - Map


Advertisements

Previous Page Next Page

C++ maps

maps are one of the most common data types in C++. It is used for storing text. It can be created by enclosing characters in double quotation marks. It can be assigned to a variable using = sign.

map Mymap = "Hello World!";

Access character of a map

A character (also called element) of a map can be accessed with it's index number. In C++, index number starts with 0 in forward direction. The below figure and example describe the indexing concept of a map.

C++ - Map Functions

Capacity

FunctionsDescription
empty() Checks whether the map is empty or not.
size() Returns the length of the map in terms of bytes.
max_size() Returns the maximum length of the map.

Element Access

FunctionsDescription
at() Access an element of the map.
operator[]() Access an element of the map.

Iterators

FunctionsDescription
begin() Returns iterator pointing to the first element of the map.
end() Returns iterator pointing to the past-the-last element of the map.
rbegin() Returns reverse iterator to the last element of the map.
rend() Returns reverse iterator to the element preceding the first element of the map.
cbegin() Returns const_iterator pointing to the first element of the map.
cend() Returns const_iterator pointing to the past-the-last element of the map.
crbegin() Returns const_reverse_iterator to the last element of the map.
crend() Returns const_reverse_iterator to the element preceding the first element of the map.

Modifiers

FunctionsDescription
clear() Clears all elements of the map.

Non-member function overloads

FunctionsDescription
swap() Exchanges elements between two maps.

Previous Page Next Page
Advertisements