1. The position of string s1 in s is returned. If no position is found,-1 is returned.
# Include
# Include
Using namespace std; int main () {string s = "what are you dong"; string s1 = "are"; int position; position = s. find (s1); if (position =-1) cout <"not find" <
# Include
# Include
Using namespace std; int main () {string s = "hahahahaha"; string s1 = "a"; int position; position = s. find_first_of (s1); cout <
<
3. Search for string s1 starting from string s subscript a and return the starting position s. find (s1, a). If no result is found, return-1.
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink">
VcD4KPHByZSBjbGFzcz0 = "brush: java;"> # include
# Include
Using namespace std; int main () {string s = "have a good time"; string s1 = "good"; int position; position = s. find (s1, 3); cout <
<<
4. Search for all start positions of the character s1 in s
# Include
# Include
Using namespace std; int main () {string s = "abb"; string s1 = "a"; // char s1 = 'a'; int position = 0; int I = 0; while (position = s. find_first_of (s1, position ))! = String: npos) {cout <
<
# Include
# Include
Using namespace std; int main () {string s = "aaabcd"; string s1 = "aaafcd"; int position; position = s. find_first_not_of (s1); cout <
<
6. reverse search: returns the position of s1 in s.
# Include
# Include
Using namespace std; int main () {string s = "aaabcd"; string s1 = "abc"; int position; position = s. rfind (s1); cout <
<
References:
Http://www.jb51.net/article/37560.htm
<
<
<
<