名稱空間
變體
操作

std::basic_string<CharT,Traits,Allocator>::rend, std::basic_string<CharT,Traits,Allocator>::crend

來自 cppreference.com
< cpp‎ | string‎ | basic_string
 
 
 
std::basic_string
 
reverse_iterator rend();
(1) (C++11 起無異常丟擲)
(C++20 起為 constexpr)
const_reverse_iterator rend() const;
(2) (C++11 起無異常丟擲)
(C++20 起為 constexpr)
const_reverse_iterator crend() const noexcept;
(3) (C++11 起)
(C++20 起為 constexpr)

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

range-rbegin-rend.svg

目錄

[編輯] 引數

(無)

[編輯] 返回值

指向最後一個字元後面字元的逆向迭代器。

[編輯] 複雜度

常數時間。

[編輯] 注意

libc++ 將 crend() 反向移植到 C++98 模式。

[編輯] 示例

#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
 
int main()
{
    std::string p("[A man, a plan, a canal: Panama]");
    std::string q;
 
    std::copy(p.crbegin(), p.crend(), std::back_inserter(q));
    std::cout << "q = " << q << '\n';
 
    std::copy(q.crbegin(), q.crend(), p.rbegin());
    std::cout << "p = " << p << '\n';
}

輸出

q = ]amanaP :lanac a ,nalp a ,nam A[
p = ]amanaP :lanac a ,nalp a ,nam A[

[編輯] 參閱

返回指向起始的逆向迭代器
(public member function) [編輯]
返回指向末尾的逆向迭代器
(public member function of std::basic_string_view<CharT,Traits>) [編輯]