GeezerVison is showing cpprefjp.github.io — std::basic_string_view::rfind - cpprefjp C++日本語リファレンス
最終更新日時:
2026年09月11日 13時06分31秒 (JST)
Akira Takahashi
が更新
履歴
編集
function
<string_view>
std:: basic_string_view:: rfind (C++17)
constexpr size_type rfind ( basic_string_view s , size_type pos = npos ) const noexcept ; // (1)
constexpr size_type rfind ( CharT c , size_type pos = npos ) const noexcept ; // (2)
constexpr size_type rfind ( const CharT * s , size_type pos , size_type n ) const ; // (3)
constexpr size_type rfind ( const CharT * s , size_type pos = npos ) const ; // (4)
概要
最後に現れる指定文字列を検索する。
(1) : 指定した位置posより前で、*thisに含まれる部分文字列svが最後に現れる位置を検索する
(2) : 指定した位置posより前で、*thisに含まれる文字cが最後に現れる位置を検索する
(3) : 指定した位置posより前で、*thisに含まれる部分文字列sの先頭n文字が最後に現れる位置を検索する
(4) : 指定した位置posより前で、*thisに含まれる部分文字列sが最後に現れる位置を検索する
戻り値
(1) : 見つかればその位置を返し、見つからない場合は basic_string_view::npos を返す。
(2) : return rfind(basic_string_view(&c, 1), pos);
(3) : return rfind(basic_string_view(s, n), pos);
(4) : return rfind(basic_string_view(s), pos);
例外
備考
pos は比較対象となる最後の文字位置では無いことに注意。(例を参照)
文字列の一致は、文字列の各文字について traits_type::eq() を用いて検査される。
例えば、(1) の形式の場合、以下のような条件を満たす最大の xpos を求める。
xpos <= pos かつ xpos + sv.size() <= size()
0 <= I かつ I < sv.size() を満たす全ての I について、traits_type::eq(at(xpos + I), sv.at(I))
(4) の形式の場合、s の文字列長は traits_type::length(s) で求められる。
例
出力
(1) : found 7
(2) : found 7
(3) : found 4
(4) : found 7
バージョン
言語
処理系