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 告别祝福语长篇简短