++


search_n()


template< class ForwardIterator, class Size, class Type >

ForwardIterator

search_n( ForwardIterator first, ForwardIterator last,

Size count, const Type &value );

template< class ForwardIterator, class Size,

class Type, class BinaryPredicate >

ForwardIterator

search_n( ForwardIterator first, ForwardIterator last,

Size count, const Type &value, BinaryPredicate pred );

search_n() [first,last) , count value. , last. , ss Mississippi value 's', count 2. ssi, value "ssi", count 2. search_n() value. ,   .

#include <algorithm>

#include <vector>

#include <iostream.h>

 

/* :

'o': o o

'mou': m o u

*/

int main()

{

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

 

const char blank = ' ';

const char oh = 'o';

 

char str[ 26 ] = "oh my a mouse ate a moose";

char *found_str = search_n( str, str+25, 2, oh );

cout << " 'o': ";

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

 

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

// ,

// : mou of mouse

vector< char, allocator >::iterator iter;

iter = search_n( vec.begin(), vec.end(), 3,

blank, not_equal_to< char >() );

 

cout << " 'mou': ";

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

}




- -  - -  - -