Finds the first object with a specified value with algorithm find() - C++ STL Algorithm

C++ examples for STL Algorithm:find

Description

Finds the first object with a specified value with algorithm find()

Demo Code

#include <iostream>
#include <algorithm>                   //for find()
using namespace std;
int arr[] = { 11, 22, 33, 44, 55, 66, 77, 88 };
int main()/*from  w  ww .  j av  a2 s  .com*/
{
   int* ptr;
   ptr = find(arr, arr+8, 33);          //find first 33
   cout << "First object with value 33 found at offset " << (ptr-arr) << endl;
   return 0;
}

Result


Related Tutorials