How to search an element with specific value in a list using C++

1 Answer

0 votes
#include <iostream>
#include <list>

using std::list;
using std::cout;
using std::endl;

int main()
{
	list<int> lst{ 1, 3, 8, 23, 88, 12, 99, 7 };

	list<int>::iterator pos;

	pos = find(lst.begin(), lst.end(), 88);

	if (pos != lst.end()) {
		cout << "found" << endl;
	}
	else {
		cout << "not found" << endl;
	}
}


/*
run:

found

*/

 



answered Jan 20, 2018 by avibootz

Related questions

3 answers 287 views
1 answer 223 views
1 answer 195 views
1 answer 166 views
1 answer 151 views
...