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 入住酒店文案祝福语简短