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 给外婆敬酒祝福语简短