vector.rend
C ++ vector :: rend()函数 (C++ vector::rend() function)
vector::rend() is a library function of "vector" header, it is used to get the first element of a vector using reverse_iterator, it returns a reverse iterator pointing to the element preceding the first element (i.e. reverse ending) of a vector.
vector :: rend()是“ vector”头文件的库函数,用于使用reverse_iterator获取向量的第一个元素,它返回一个反向迭代器,该迭代器指向a的第一个元素之前的元素(即,反向结尾)。向量。
Note: To use vector, include <vector> header.
注意:要使用向量,请包含<vector>标头。
Syntax of vector::rend() function
vector :: rend()函数的语法
vector::rend();
Parameter(s): none – It accepts nothing.
参数: 无 –不接受任何内容。
Return value: iterator – It returns an iterator pointing to the element preceding the first elements of the vector.
返回值: iterator –返回一个迭代器,该迭代器指向向量的第一个元素之前的元素。
Example:
例:
Input:
vector<int> vector1{ 1, 2, 3, 4, 5 };
Function call:
vector<int>::reverse_iterator rit;
rit = vector1.rend()-1;
cout << *rit;
Output:
1
C ++程序演示vector :: rend()函数的示例 (C++ program to demonstrate example of vector::rend() function)
//C++ STL program to demonstrate example of
//vector::rend() function
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> v1;
v1.push_back(10);
v1.push_back(20);
v1.push_back(30);
v1.push_back(40);
v1.push_back(50);
//creating iterator
vector<int>::reverse_iterator rit;
rit = v1.rend()-1;
cout << "first element is: " << *rit << endl;
return 0;
}
Output
输出量
first element is: 10
Reference: C++ vector::rend()
翻译自: https://www.includehelp.com/stl/vector-rend-function-with-example.aspx
vector.rend