Export (0) Print
Expand All
5 out of 10 rated this helpful - Rate this topic

find

Locates the position of the first occurrence of an element in a range that has a specified value.

template<class InputIterator, class Type>
   InputIterator find(
      InputIterator _First, 
      InputIterator _Last, 
      const Type& _Val
   );

Parameters

_First
An input iterator addressing the position of the first element in the range to be searched for the specified value.
_Last
An input iterator addressing the position one past the final element in the range to be searched for the specified value.
_Val
The value to be searched for.

Return Value

An input iterator addressing the first occurrence of the specified value in the range being searched. If no such value exists in the range, the iterator returned addresses the last position of the range, one past the final element.

Remarks

The operator== used to determine the match between an element and the specified value must impose an equivalence relation between its operands.

Example

// alg_find.cpp
// compile with: /EHsc 
#include <list>
#include <algorithm>
#include <iostream>

int main( )
{
   using namespace std;

   list <int> L;
   list <int>::iterator Iter;
   list <int>::iterator result;
   
   L.push_back( 40 );
   L.push_back( 20 );
   L.push_back( 10 );
   L.push_back( 40 );
   L.push_back( 10 );

   cout << "L = ( " ;
   for ( Iter = L.begin( ) ; Iter != L.end( ) ; Iter++ )
      cout << *Iter << " ";
   cout << ")" << endl;
   
   result = find( L.begin( ), L.end( ), 10 );
   if  ( result == L.end( ) )
      cout << "There is no 10 in list L." << endl;
   else
      result++;
      cout << "There is a 10 in list L and it is"
           << " followed by a " << *(result) << "." << endl;
}

Output

L = ( 40 20 10 40 10 )
There is a 10 in list L and it is followed by a 40.

See Also

<algorithm> Members | find Sample

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.