Vector crbegin() in C++ STL Last Updated : 28 Nov, 2024 Comments Improve Suggest changes Like Article Like Report 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: C++ #include <bits/stdc++.h> using namespace std; int main() { vector<int> v = {1, 3, 5, 2, 4}; // Access the last elemement (reverse beginning) cout << *v.crbegin(); return 0; } Output4This article covers the syntax, usage, and common examples of the vector crbegin() method in C++.Table of ContentSyntax of Vector crbegin()Supported Iterator OperationsExamples of Vector crbegin()Reverse Iterate Over a VectorSyntax of Vector crbegin()The vector crbegin() is a member method of the std::vector class defined inside the <vector> header file.v.crbegin();Parameters:This method does not take any parameters.Return Value:Returns a constant reverse iterator pointing to the last element of the vector.Supported Iterator OperationsThe 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:Incrementing (++)Decrementing (--)Adding/Subtracting integersSubtraction of another iterator of the same containerComparison of iteratorsDereferenceAs a constant iterator, it cannot modify the elements it points to. Attempting to modify elements results in a compilation error.Examples of Vector crbegin()This method is typically used with vector crend() to iterate over the vector in reverse without modifying its elements. Below are some examples:Reverse Iterate Over a Vector C++ #include <bits/stdc++.h> using namespace std; int main() { vector<int> v = {1, 3, 5, 2, 4}; // Reverse iterate using crbegin() and crend() for (auto it = v.crbegin(); it != v.crend(); ++it) cout << *it << " "; return 0; } Output4 2 5 3 1 Comment More infoAdvertise with us Next Article Vector crbegin() in C++ STL A abhishekcpp Follow Improve Article Tags : C++ STL cpp-vector cpp-containers-library Practice Tags : CPPSTL Similar Reads Vector crend() in C++ STL In C++, the vector crend() is a built-in method used to obtain a constant reverse iterator pointing to the theoretical element just before the first element of the vector. It is used to mark the reverse end of the vector.Letâs take a look at an example: C++#include <bits/stdc++.h> using namesp 2 min read Vector begin() in C++ STL In C++, the vector begin() is a built-in method used to obtain an iterator pointing to the start of the vector. This iterator is used to traverse the vector or perform operations starting from the beginning of the vector.Letâs take a look at an example that illustrates the use of the vector begin() 4 min read Vector end() in C++ STL In C++, the vector end() is a built-in method used to obtain an iterator pointing to the theoretical element after the last element of the vector. Even though this iterator does not point to a valid element, it serves as a marker for the end of the vector.Letâs take a look at an example that illustr 3 min read Vector front() in C++ STL In C++, the vector front() is a built-in function used to retrieve the first element of the vector. It provides a reference to the first element, allowing you to read or modify it directly.Letâs take a quick look at a simple example that uses the vector front() method:C++#include <bits/stdc++.h 2 min read Vector erase() in C++ STL In C++, vector erase() is a built-in function that is used to delete elements from the vector. It removes an element of a specific position or range of elements from the vector. Letâs take a simple example that uses the vector erase() method:C++#include <bits/stdc++.h> using namespace std; int 3 min read Like