In writing a C + + program, there is always the case of finding a small string from a string, for in C we often use either strstr () or STRCHR (). For C + + strings, we tend to use find ().
C + +: #inlcude <string>
C: #include <string.h>
Find (): finds a specified single character or array of characters in a string. Returns the starting position of the first match if found, and returns String::npos if no matching content is found.
Find_first_of (): In a target string, the return value is the first character position to match any character in the specified character group. If no matching content is found, the NPOs is returned.
Find_last_of (): Finds in a target string, returning the last character position that matches any character in the specified character group. If no matching content is found, the NPOs is returned.
Find_first_not_of (): Finds in a target string and returns the position of the first element that does not match any of the characters in the specified character group. Returns NPOs if no such element is found.
Find_last_not_of (): Finds in a target string, returning the position of the element with the largest subscript value that does not match any of the characters in the specified character group. Returns NPOs if no such element is found.
RFind (): Finds a specified single character or group of characters on a string from tail to head. Returns the starting position of the first match if found, and returns NPOs if no matching content is found.
Find (string, int): The first parameter is used to indicate the character to be looked up, and the second parameter is used to indicate where to start looking for substrings from the string (the default lookup position is 0).
Example: string matching :
1#include"stdafx.h"2#include <iostream>3#include <math.h>4#include <string>5 using namespacestd;6 7 int_tmain (intARGC, _tchar*argv[])8 {9 stringT//Original StringTen stringP//Mode One while(cin>>t>>P) A { - intCount=0; - intbegin=-1; the while((Begin=t.find (p,begin+1))!=string:: NPOs) - { -count++; - } +cout<<count<<Endl; - } + intZ; ACin>>Z; at return 0; -}
Reprint please indicate source: http://www.cnblogs.com/fnlingnzb-learner/p/5831454.html
C + + string string lookup match