Use find algorithm to find an element in a list
#include <iostream>
#include <cassert>
#include <algorithm>
#include <list>
#include <iterator>
using namespace std;
int main()
{
int a[10] = {12, 3, 25, 7, 11, 213, 7, 123, 29, -31};
list<int> list1(&a[0], &a[10]);
// Find the first element equal to 7 in list1:
list<int>::iterator i = find(list1.begin(),list1.end(),7);
assert (*i == 7 && *(++i) == 11);
cout << *i;
return 0;
}
/*
11
*/
Related examples in the same category