Javatpoint Logo
Javatpoint Logo

C++ Deque at()

C++ Deque at() function is used to access the element at specified position pos.

Note: If pos is greater than the size of the container, then the function throws an exception i.e "out of range".



pos: It defines the position of an element which is to be returned.

where, size_type is an unsigned integral type.

Return value

It returns the reference of the specified element.

Example 1

Let's see a simple example



Example 2

Let's see a simple example


terminate called after throwing an instance of 'std::out_of_range'

In this example, at() function tries to access the element which is beyond the size of the container. Therefore, it throws an exception i.e out of range.

Next TopicC++ Deque

Please Share

facebook twitter google plus pinterest