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

履歴 編集

function
<string>

std::basic_string::crend(C++11)

const_reverse_iterator crend() const noexcept;           // (1) C++11
constexpr const_reverse_iterator crend() const noexcept; // (1) C++20

概要

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

戻り値

reverse_iterator(begin())

例外

投げない

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

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

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

出力

o
l
l
e
h

参照