![]() |
VOOZH | about |
In C++, the vector crbegin() is a built-in method used to obtain a constant reverse iterator pointing to the last element of the vector. It is used to mark the starting point of reverse iteration over the vector without modifying its elements.
Let’s take a look at an example:
4
This article covers the syntax, usage, and common examples of the vector crbegin() method in C++.
Table of Content
The vector crbegin() is a member method of the std::vector class defined inside the <vector> header file.
v.crbegin();
Parameters:
Return Value:
The vector crbegin() function returns a constant reverse iterator of type vector::const_reverse_iterator. Being a reverse random access iterator, it supports reverse traversal and arithmetic operations such as:
As a constant iterator, it cannot modify the elements it points to. Attempting to modify elements results in a compilation error.
This method is typically used with vector crend() to iterate over the vector in reverse without modifying its elements. Below are some examples:
4 2 5 3 1