#include <iostream>
#include <list>
using namespace std;
bool Predicate(int n){
return n >= 30;
}
int main(){
list<int> lt;
lt.push_back(10);
lt.push_back(20);
lt.push_back(30);
lt.push_back(40);
lt.push_back(50);
list<int>::iterator iter;
for (iter = lt.begin(); iter != lt.end(); ++iter){
cout << *iter << ' ';
}
cout << endl;
iter = lt.begin();
iter++;
iter++;
// erase 삭제
list<int>::iterator iter2 = lt.erase(iter);
for (iter = lt.begin(); iter != lt.end(); ++iter){
cout << *iter << ' ';
}
cout << endl;
cout << "iter2 : " << *iter2 << endl;
lt.push_back(10);
lt.push_back(10);
for (iter = lt.begin(); iter != lt.end(); ++iter){
cout << *iter << ' ';
}
cout << endl;
// 리스트에서 원소 10 제거
lt.remove(10);
for (iter = lt.begin(); iter != lt.end(); ++iter){
cout << *iter << ' ';
}
cout << endl;
// Predicate 함수에 해당하는 원소 제거 (30보다 크다)
lt.remove_if(Predicate);
for (iter = lt.begin(); iter != lt.end(); ++iter){
cout << *iter << ' ';
}
cout << endl;
return 0;
}
'To be Developer > C,C++' 카테고리의 다른 글
[C++]상수화 constant (0) | 2017.01.18 |
---|---|
[MFC]엔터 또는 ESC입력시 프로그램 꺼짐 방지하는법 (0) | 2017.01.18 |
[MFC] MFC에서 디버깅시 콘솔창 띄우기 (0) | 2017.01.18 |