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 ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.