Namespaces
Variants

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

ja.cppreference.net より
 
 
 
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() const noexcept;
(3) (C++11以降)
(C++20以降constexpr)

反転された文字列の最初の文字を指す逆イテレータを返します。これは、反転されていない文字列の最後の文字に対応します。

パラメータ

(なし)

戻り値

最初の文字への逆方向イテレータ。

計算量

定数。

注記

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>の公開メンバ関数)