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 婆婆高寿祝福语大全简短