函式原型
template <class ForwardIterator1, class ForwardIterator2> ForwardIterator1 find_first_of ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2 );template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> ForwardIterator1 find_first_of ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred );
函式說明
查找在字元串中第一個與指定字元串中的某個字元匹配的字元,返回它的位置。
函式套用舉例
// find_first_of example#include <iostream>#include <algorithm> // find_first_of 所在的頭檔案!#include <cctype>#include <vector>usingnamespace std;bool comp_case_insensitive ( char c1, char c2 ){ return (tolower(c1)==tolower(c2));}int main (){ int mychars[] = { 'a','b','c','A','B','C' }; vector<char> myvector ( mychars, mychars+6 ); vector<char>::iterator it; int match[] = { 'A', 'B', 'C' }; // using default comparison: it = find_first_of ( myvector.begin(), myvector.end(), match, match+3 ); if ( it!=myvector.end() ) cout << "first match is: " << *it << endl; // using predicate comparison: it = find_first_of ( myvector.begin(), myvector.end(), match, match+3, comp_case_insensitive ); if ( it!=myvector.end() ) cout << "first match is: " << *it << endl; return 0;}