How to find element in a list container with int numbers in C++

1 Answer

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

int main()
{
	std::list<int> lst;

	for (int i = 10; i <= 30; i += 2) {
		lst.push_back(i);
	}
	
	auto indexvalue16 = find(lst.begin(), lst.end(), 16);
	if (lst.end() == indexvalue16)
	{
		std::cout << "item not found" << std::endl;
	}
	else
	{
		std::cout << "item found" << std::endl;
	}

	return 0;
}

/*
run:

item found

*/

 



answered Dec 30, 2017 by avibootz
...