C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ Vector crend()

C++ Vector crend()

此函数用于指向 Vector 容器中第一个元素之前的元素。

语法

请考虑 Vector 'v'。语法为:
const_reverse_iterator itr=v.crend();

参数

它不包含任何参数。

返回值

它返回常量反向迭代器指向序列的另一端。

示例1

我们来看一个简单的示例。
#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 shows that crend() function does not modify the value otherwise, it shows an error.

示例2

让我们看另一个简单的示例
#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;
}
输出:
java
在此示例中,crend()函数访问 Vector 容器的第一个元素。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4