std::basic_string<CharT,Traits,Allocator>::rend, std::basic_string<CharT,Traits,Allocator>::crend
来自 cppreference.cn
< cpp | string | basic string
reverse_iterator rend(); |
(1) | (noexcept since C++11) (constexpr since C++20) |
const_reverse_iterator rend() const; |
(2) | (noexcept since C++11) (constexpr since C++20) |
const_reverse_iterator crend() const noexcept; |
(3) | (since C++11) (constexpr since C++20) |
返回一个反向迭代器,指向反向字符串的最后一个字符之后的位置。它对应于非反向字符串的第一个字符之前的位置。此字符充当占位符,尝试访问它会导致未定义的行为。
目录 |
[编辑] 参数
(无)
[编辑] 返回值
指向最后一个字符之后的反向迭代器。
[编辑] 复杂度
常数。
[编辑] 注解
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[
[编辑] 参见
(C++11) |
返回指向开头的反向迭代器 (公共成员函数) |
返回指向末尾的反向迭代器 ( std::basic_string_view<CharT,Traits> 的公共成员函数) |