Mega Code Archive

 
Categories / C++ Tutorial / Vector
 

Find a sample integer 3 in the vector using the find algorithm

#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; }