stl list.remove_if使用
2010-07-09 11:01
405 查看
#include <cstdlib> #include <iostream> #include <list> #include <iterator> #include <algorithm> using namespace std; typedef struct _NODE { int id; string str; _NODE(int id, string str) : id(id), str(str){}; friend ostream& operator<<(ostream &os, const _NODE &nod) { return os << "(" << nod.id << ", " << nod.str << ")" << " "; } }NODE; class check { public: bool operator()(const NODE &nod) { return nod.id % 2; } }; template <class T> void _printf(const T &begin, const T &end) { ostream_iterator<NODE> os(cout, " "); copy(begin, end, os); cout << endl; } int main(int argc, char *argv[]) { list<NODE> lis; for(int i=0; i<10; i++) { string str((i % 2 == 0) ? "even" : "odd"); lis.push_back(NODE(i, str)); } cout << "original list is: " << endl; _printf(lis.begin(), lis.end()); cout <<"after remove the odd elements: " << endl; lis.remove_if(check()); _printf(lis.begin(), lis.end()); system("PAUSE"); return EXIT_SUCCESS; }
相关文章推荐
- STL 如何使用list::remove_if
- std::list<>::remove_if的使用
- C++/STL_利用remove_if 删除vector,list,deque满足条件的元素
- 关于在STL容器list中使用find_if搜索特定的节点
- 如何使用remove_copy_if() algorithm? (C/C++) (STL)
- 关于在STL容器list中使用find_if 函数
- 使用STL通用算法find_if()在list中搜索对象
- (原創) 如何使用remove_copy_if() algorithm? (C/C++) (STL)
- STL中remove_if()/find_if()/replace_if()的使用方法(The usages of remove_if()/find_if()/replace_if() )
- stl之list使用
- STL Vector remove()和erase()的使用
- 循环中使用List.remove的坑
- java.util.List的remove()方法使用技巧(转)
- STL中list的erase()方法的使用
- stl容器区别(内存布局和使用场合): vector list deque set map
- STL中list的使用(理论)
- STL学习笔记之 (五)容器 vector deque list 使用条件
- STL错误。List inset iterator out side range (对STL中使用指针引起的错误)
- STL 链表(list)的使用
- STL的remove函数和list的remove成员函数