std::basic_string<CharT,Traits,Allocator>::rbegin, std::basic_string<CharT,Traits,Allocator>::crbegin

来自cppreference.com
< cpp‎ | string‎ | basic string
 
 
 
std::basic_string
 
reverse_iterator rbegin();
(1) (C++11 起为 noexcept)
(C++20 起为 constexpr)
const_reverse_iterator rbegin()const;
(2) (C++11 起为 noexcept)
(C++20 起为 constexpr)
const_reverse_iterator crbegin()constnoexcept;
(3) (C++11 起)
(C++20 起为 constexpr)

返回指向逆向字符串的首字符的逆向迭代器。它对应非逆向字符串的末字符。

range-rbegin-rend.svg

目录

[编辑]参数

(无)

[编辑]返回值

指向首字符的逆向迭代器。

[编辑]复杂度

常数。

[编辑]注解

libc++ 将 crbegin() 向后移植到 C++98 模式。

[编辑]示例

#include <iostream>#include <algorithm>#include <iterator>#include <string>   int main(){std::string s("Exemplar!");*s.rbegin()='y';std::cout<< s <<'\n';// "Exemplary"   std::string c;std::copy(s.crbegin(), s.crend(), std::back_inserter(c));std::cout<< c <<'\n';// "yralpmexE"}

输出:

Exemplary yralpmexE

[编辑]参阅

(C++11)
返回指向末尾的逆向迭代器
(公开成员函数)[编辑]
返回指向起始的反向迭代器
(std::basic_string_view<CharT,Traits> 的公开成员函数)[编辑]
close