在这里,我们将看到C ++ STL中的数组crbegin()和crend()函数。
array::crbegin()函数用于获取反向迭代器。它返回常量反向迭代器,指向容器的最后一个元素。此函数不带任何参数。
array::crend()函数的作用与之相反crbegin()。这将返回迭代器,该迭代器指向反向迭代器的最后一个元素。
让我们看一些代码示例以获得更好的主意。
#include<iostream>
#include<array>
using namespace std;
main() {
array<int, 10> arr = {00, 11, 22, 33, 44, 55, 66, 77, 88, 99};
cout << "The list in reverse order: ";
for(auto it = arr.crbegin(); it != arr.crend(); it++){
cout << *it << " ";
}
}输出结果
The list in reverse order: 99 88 77 66 55 44 33 22 11 0