The find_last_of() Family

The find_last_of() methods have these prototypes:

size_type find_last_of (const basic_string& str,                        size_type pos = npos) const noexcept;size_type find_last_of (const charT* s, size_type pos, size_type n) const;size_type find_last_of (const charT* s, size_type pos = npos) const;size_type find_last_of (charT c, size_type pos = npos) const noexcept;

These methods work like the corresponding rfind() methods, except that instead of looking for a match of the entire substring, they look for the last match for any single character in the substring.

Here’s code for finding the location of the last and next to last occurrences of any of the letters in "fluke" in a longer string:

string longer("That is a ...

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.