list 中删除满足某个条件的所有记录

#include "stdafx.h"
#include "Singlelist.h"
#include <list>
using namespace std;

typedef list<int> LIST;
typedef LIST::iterator ITERATOR;


int _tmain(int argc, _TCHAR* argv[])
{
	
	LIST mylist;


	for(int i=0; i<10; i++)
	{
		mylist.push_back(i);
	}
	
	ITERATOR LI;
	for(LI = mylist.begin(); LI != mylist.end();)
	{
		if (((*LI) % 2) !=0)
		{
			
			LI = mylist.erase(LI);
		}
		else
		{
			LI++;
		}
	}

	for(LI = mylist.begin(); LI != mylist.end(); LI++)
	{
		printf("%d\n", *LI);
	}
	getchar();

}

你可能感兴趣的:(list 中删除满足某个条件的所有记录)