The find() Family
Here are the find() prototypes as provided by C++11:
size_type find (const basic_string& str, size_type pos = 0) const noexcept;size_type find (const charT* s, size_type pos = 0) const;size_type find (const charT* s, size_type pos, size_type n) const;size_type find (charT c, size_type pos = 0) const noexcept;
The first member returns the beginning position of the str substring’s first occurrence in the invoking object, with the search beginning at 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:
string longer("That is a funny hat.");string shorter("hat");size_type loc1 = longer.find(shorter); // sets loc1 to 1size_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