The find_first_of() Family

The find_first_of() methods have these prototypes:

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

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

string longer("That is a funny hat.");string shorter("fluke");size_type loc1 = longer.find_first_of(shorter);  // sets loc1 to 10size_type loc2 = longer.find_first_of("fat");    // ...

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.