名稱空間
變體
操作

std::array<T,N>::rend, std::array<T,N>::crend

來自 cppreference.com
< cpp‎ | 容器‎ | array
 
 
 
 
reverse_iterator rend() noexcept;
(1) (C++11 起)
(自 C++17 起為 constexpr)
const_reverse_iterator rend() const noexcept;
(2) (C++11 起)
(自 C++17 起為 constexpr)
const_reverse_iterator crend() const noexcept;
(3) (C++11 起)
(自 C++17 起為 constexpr)

返回一個反向迭代器,指向反向 array 的最後一個元素之後的元素。它對應於非反向 array 的第一個元素之前的元素。此元素充當佔位符,嘗試訪問它會導致未定義行為。

range-rbegin-rend.svg

目錄

[編輯] 返回值

指向最後一個元素之後位置的逆向迭代器。

[編輯] 複雜度

常數時間。

[編輯] 示例

#include <algorithm>
#include <iostream>
#include <array>
 
int main()
{
    std::array<int, 11> a{1, 11, 11, 35, 0, 12, 79, 76, 76, 69, 40};
 
    // Print elements of container in reverse order using const_reverse_iterator's.
    std::for_each(a.crbegin(), a.crend(), [](int e){ std::cout << e << ' '; });
    std::cout << '\n';
 
    // Modify each element of container using non-const reverse_iterator's.
    std::for_each(a.rbegin(), a.rend(), [](int& e){ e += 32; });
 
    // Print elements as chars in reverse order using const_reverse_iterator's.
    std::for_each(a.crbegin(), a.crend(), [](char e){ std::cout << e; });
    std::cout << '\n';
}

輸出

40 69 76 76 79 12 0 35 11 11 1
Hello, C++!

[編輯] 參閱

返回指向起始的逆向迭代器
(public member function) [編輯]
(C++14)
返回容器或陣列的反向結束迭代器
(function template) [編輯]