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

来自cppreference.com
< cpp‎ | string‎ | basic string
 
 
 
std::basic_string
成员函数
元素访问
迭代器
basic_string::rendbasic_string::crend
(C++11)
容量
修改器
搜索
操作
常量
非成员函数
I/O
比较
(C++20 前)(C++20 前)(C++20 前)(C++20 前)(C++20 前)(C++20)
数值转换
(C++11)(C++11)(C++11)
(C++11)(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
字面量
辅助类
推导指引 (C++17)

 
reverse_iterator rend();
(1) (C++11 起为 noexcept)
(C++20 起为 constexpr)
const_reverse_iterator rend() const;
(2) (C++11 起为 noexcept)
(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[

参阅

返回指向起始的逆向迭代器
(公开成员函数)
返回指向结尾的反向迭代器
(std::basic_string_view<CharT,Traits> 的公开成员函数)