The rfind() Family
The rfind() methods have these prototypes:
size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;size_type rfind(const charT* s, size_type pos = npos) const;size_type rfind(const charT* s, size_type pos, size_type n) const;size_type rfind(charT c, size_type pos = npos) const noexcept;
These methods work like the analogous find() methods, except that they find the last occurrence of a string or character that starts at or before position pos. If the substring is not found, the method returns npos.
Here’s code for finding the location of the substring "hat" in a longer string, starting at the end of the longer string:
string longer("That is a funny hat.");string shorter("hat");size_type ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access