最終更新日時(UTC):
が更新

履歴 編集

function
<string>

std::basic_string::rend

reverse_iterator rend();                      // (1) C++03
reverse_iterator rend() noexcept;             // (1) C++11
constexpr reverse_iterator rend() noexcept;   // (1) C++20

const_reverse_iterator rend() const;                    // (2) C++03
const_reverse_iterator rend() const noexcept;           // (2) C++11
constexpr const_reverse_iterator rend() const noexcept; // (2) C++20

概要

先頭の前を指す逆イテレータを取得する。

戻り値

reverse_iterator(begin())

例外

投げない

#include <iostream>
#include <string>
#include <algorithm>

int main()
{
  std::string s = "hello";

  // 文字列オブジェクトsに含まれる、全ての要素を逆順に出力
  std::for_each(s.rbegin(), s.rend(), [](char c) {
    std::cout << c << std::endl;
  });
}

出力

o
l
l
e
h

参照