Find a sample integer '3' in the vector using the 'find' algorithm : vector find « vector « C++ Tutorial






#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
template <typename elementType>
bool IsEven (const elementType& number)
{
    return ((number % 2) == 0);
}

int main ()
{
    vector <int> v;

    for (int nNum = -9; nNum < 10; ++ nNum)
        v.push_back (nNum);

    vector <int>::const_iterator i;
    for ( i = v.begin (); i != v.end (); ++ i )
        cout << *i << ' ';

    cout << v.size () << "' elements" << endl;

    // Find a sample integer '3' in the vector using the 'find' algorithm
    vector <int>::iterator iFound;
    iFound = find ( v.begin ()    // Start of range
                  , v.end ()    // End of range
                  , 3 );             // Element to find

    return 0;
}








16.14.vector find
16.14.1.Locate maximum element in a vector
16.14.2.Locate minimum element in a vector
16.14.3.find the smallest number
16.14.4.Find a sample integer '3' in the vector using the 'find' algorithm
16.14.5.Find the first even number in the collection
16.14.6.Demonstrating the generic find algorithm with a vector