C ++ STL中带有示例的array :: rbegin()和array :: rend()函数
C++STLarray::rbegin()和array::rend()函数
array::rbegin()函数是array的库函数,用于获取数组的第一个元素(从反面),它返回指向数组最后一个元素的反向迭代器。
array::rend()函数是array的库函数,用于获取数组的最后一个元素(从反面,即第一个元素),它返回指向数组最后一个元素的反向迭代器。
语法:
array::rbegin();
array::rend();参数:无
返回值:函数返回指向数组的第一个和最后一个元素的反向迭代器。
示例
Input or array declaration:
array<int,5> arr {10, 20, 30, 40, 50};
Function call:
auto it=arr.rbegin();
cout<<*it;
it=arr.rend();
cout<<*it;
Output:
50 10C++STL程序演示array::rbegin()和array::rend()函数的示例
#include <array>
#include <iostream>
using namespace std;
int main(){
array<int,5> numbers {10, 20, 30, 40, 50};
array<string,5> cities {"New Delhi", "Mumbai", "Gwalior"};
cout<<"Elements of numbers array..."<<endl;
for(auto it=numbers.rbegin(); it!=numbers.rend(); it++)
cout<<*it<<" ";
cout<<endl;
cout<<"Elements of cities array..."<<endl;
for(auto it=cities.rbegin(); it!=cities.rend(); it++)
cout<<*it<<" ";
cout<<endl;
return 0;
}输出结果
Elements of numbers array... 50 40 30 20 10 Elements of cities array... Gwalior Mumbai New Delhi
热门推荐
10 小学毕业父母简短祝福语
11 幼儿生日祝福语模板简短
12 新娘妈妈的祝福语简短
13 邻居聚会祝福语大全简短
14 十条祝福语简短
15 给同学祝福语的简短
16 过年祝福语简短祝妈妈
17 祝女儿简短祝福语大全
18 恩师诗词祝福语简短大全