Access

In this lesson, we'll discuss the method used to access the elements of a container.

To access the elements of a container, we can use an iterator. A begin and end iterator forms a range, which can be processed further. For a container cont, cont.begin() is the begin iterator and cont.end() is the end iterator, which defines a half-open range. It is half-open because the begin iterator belongs to the range, the end iterator refers to a position past the range. With the iterator pair cont.begin() and cont.end() we can modify the elements.

Iterator Description
cont.begin() and cont.end() Pair of iterators to iterate forward.
cont.cbegin() and cont.cend() Pair of iterators to iterate const forward.
cont.rbegin() and cont.rend() Pair of iterators to iterate backward.
cont.crbegin() and cont.crend() Pair of iterators to iterate const backward.

Functions available for iterators in containers

Now I can modify the container.