++


search()


template< class ForwardIterator1, class ForwardIterator2 >

ForwardIterator

search( ForwardIterator1 first1, ForwardIterator1 last1,

ForwardIterator2 first2, ForwardIterator2 last2 );

 

template< class ForwardIterator1, class ForwardIterator2,

class BinaryPredicate >

ForwardIterator

search( ForwardIterator1 first1, ForwardIterator1 last1,

ForwardIterator2 first2, ForwardIterator2 last2,

BinaryPredicate pred );

, search() , [first1,last1), . , last1. , Mississippi iss , search() , . ,   .

#include <algorithm>

#include <vector>

#include <iostream.h>

 

/* :

'ate': a t e

'vat': v a t

*/

 

int main()

{

ostream_iterator< char > ofile( cout, " " );

char str[ 25 ] = "a fine and private place";

char substr[] = "ate";

char *found_str = search(str,str+25,substr,substr+3);

 

cout << " 'ate': ";

copy( found_str, found_str+3, ofile ); cout << '\n';

vector< char, allocator > vec( str, str+24 );

vector< char, allocator > subvec(3);

 

subvec[0]='v'; subvec[1]='a'; subvec[2]='t';

vector< char, allocator >::iterator iter;

iter = search( vec.begin(), vec.end(),

subvec.begin(), subvec.end(),

equal_to< char >() );

 

cout << " 'vat': ";

copy( iter, iter+3, ofile ); cout << '\n';

}




- -  - -  - -