命名空间
变体
操作

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

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

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

range-rbegin-rend.svg

目录

[编辑] 参数

(无)

[编辑] 返回值

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

[编辑] 复杂度

常数。

[编辑] 注解

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

[编辑] 示例

#include <algorithm>
#include <iostream>
#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> 的公共成员函数) [编辑]