array::crbegin()
是C++ STL中的内置函数, 它返回一个常量反向迭代器, 指向容器中的最后一个元素。
语法如下:
array_name.crbegin()
参数:该函数不接受任何参数。
返回值:该函数返回指向容器中最后一个元素的反向迭代器。
程序演示array::crbegin()方法:
程序1:
//CPP program to illustrate
//the array::crbegin() function
#include <
bits/stdc++.h>
using namespace std;
int main()
{
//array initialisation
array<
int , 5>
arr = { 1, 5, 2, 4, 7 };
//prints the last element
cout <
<
"The last element is " <
<
*(arr.crbegin()) <
<
endl;
//prints all the elements
cout <
<
"The array elements in reverse order are:\n" ;
for ( auto it = arr.crbegin();
it != arr.crend();
it++)
cout <
<
*it <
<
" " ;
return 0;
}
输出如下:
The last element is 7
The array elements in reverse order are:
7 4 2 5 1
array::crend()
是C++ STL中的内置函数, 它返回一个常数反向迭代器, 该迭代器指向数组容器中第一个元素之前的理论元素。
语法如下:
array_name.crend()
参数:该函数不接受任何参数。
【C++ STL中的array::crbegin()和array::crend()】返回值:该函数返回一个常量反向迭代器, 该迭代器指向数组容器中第一个元素之前的理论元素。
程序演示array::crend()方法:
程序1:
//CPP program to illustrate
//the array::crend() function
#include <
bits/stdc++.h>
using namespace std;
int main()
{
array<
int , 5>
arr = { 1, 5, 2, 4, 7 };
//prints all the elements
cout <
<
"The array elements in reverse order are:\n" ;
for ( auto it = arr.crbegin();
it != arr.crend();
it++)
cout <
<
*it <
<
" " ;
return 0;
}
输出如下:
The array elements in reverse order are:
7 4 2 5 1
推荐阅读
- 使用Django REST框架实现令牌认证
- 数字和等于其所有素数的数字之和的数字
- Python使用Django进行表单验证项目示例
- Python Django-allauth设置和配置
- [L,R]范围内的数字计数,其中至少包含一个除以K的数字
- 从BST构建二叉树,使其遍历级别顺序可打印排序的数据
- 将二进制字符串拆分为0和1相等数量的子字符串
- win10变回win7图文详细教程图解
- 本图文详细教程教你各版本Ghost windows10系统激活码密钥