When pos is specified the search only includes characters on or after position pos, ignoring any possible occurrences in previous locations.
Notice that unlike member find_first_of, whenever more than one character is being searched for, it is not enough that only one of these characters match, but the entire sequence of characters to find must be matched.
Parameters
- str
- string to be searched for in the object. The entire content of str must be matched in some part of the string to be considered a match.
- s
- Array with a sequence of characters.
In the second member function version, the size of the content to be matched is only determined by parameter n.
In the third version, a null-terminated sequence is expected, therefore its end is determined by the first occurrence of a null character in it. - n
- Length of sequence of characters to search for.
- c
- Individual character to be searched for.
- pos
- Position of the first character in the string to be taken into consideration for possible matches. A value of 0 means that the entire string is considered.
Return Value
The position of the first occurrence in the string of the searched content.If the content is not found, the member value npos is returned.
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
Notice how parameter pos can be used to search for a second instance of the same search string. Output:
first 'needle' found at: 14 second 'needle' found at: 44 'haystack' also found at: 30 Period found at: 51 There are two prepositions in this haystack with needles. |
Basic template member declarations
( basic_string<charT,traits,Allocator> )| 1 2 3 4 5 |
|
See also
| string::rfind | Find last occurrence of content in string (public member function) |
| string::find_first_of | Find character in string (public member function) |
| string::find_last_of | Find character in string from the end (public member function) |
| string::find_first_not_of | Find absence of character in string |
| string::find_last_not_of | Find absence of character in string from the end (public member function) |
| string::replace | Replace part of string (public member function) |
| string::substr | Generate substring (public member function) |
