English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This function is used to point to the reverse iterator of the vector (vector) container, returning a const_iterator pointing to the first element of the container.
The syntax of the vector (vector) "v" is:
const_reverse_iterator itr = v.crend();
It does not contain any parameters.
It returns a constant reverse iterator that points to the reverse end of the sequence.
Let's look at a simple example.
#include <iostream> #include<vector> using namespace std; int main() { vector<int> v{1,2,3,4,5; vector<int>::const_reverse_iterator itr = v.crend();-2; *itr=9; cout<<*itr; return 0; } //In this example, it indicates that the crend() function does not modify the value, otherwise, it will display an error.
Let's take another simple example
#include <iostream> #include<vector> using namespace std; int main() { vector<string>str{"java","C","C++,".Net"}; vector<string>::const_reverse_iterator itr = str.crend()-1; std::cout<< *itr; return 0; }
Output:
java
In this example, the crend() function accesses the first element of the vector (vector) container.