目录

vector::rend

描述 (Description)

C ++函数std::vector::rend()返回一个反向迭代器,它指向向量的反向末端,即向量的开头。

声明 (Declaration)

以下是std :: vector :: rend()函数形式std :: vector标头的声明。

C++98

reverse_iterator rend();
const_reverse_iterator rend() const;

C++11

reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;

参数 (Parameters)

没有

返回值

如果object是常量限定的,则返回常量反转器迭代器,否则返回非常量反向迭代器。

异常 (Exceptions)

这个成员函数永远不会引发激发。

时间复杂

常数即O(1)

例子 (Example)

以下示例显示了std :: vector :: rend()函数的用法。

#include <iostream>
#include <vector>
using namespace std;
int main(void) {
   vector<int> v = {1, 2, 3, 4, 5};
   /* Iterate vector */
   for (auto it =  v.rend() - 1; it >= v.rbegin(); --it)
      cout << *it << endl;
   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

1
2
3
4
5
↑回到顶部↑
WIKI教程 @2018