How to remove all elements that equal to N from a list in C++

1 Answer

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

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

int main() 
{
	std::list<int> lst({ 2, 3, 4, 5, 2, 9, 2, 12, 2, 2 });

	lst.remove(2);

	for (int val : lst)
		cout << val << endl;

	return 0;
}

/*
run:

3
4
5
9
12

*/

 



answered Feb 16, 2018 by avibootz
...