首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

怎么使用STL中的list:remove_if()函数呀

2012-02-25 
如何使用STL中的list::remove_if()函数呀list::remove_if()函数的参数是怎么回事,我有点看不懂,有哪位高手

如何使用STL中的list::remove_if()函数呀
list::remove_if()函数的参数是怎么回事,我有点看不懂,有哪位高手给我指教下,最好给出完整的简洁实例。谢谢各位了!

[解决办法]
看看这个
http://blog.csdn.net/steven_wang787/archive/2009/09/03/4513121.aspx
[解决办法]

C/C++ code
#include <iostream>#include <list>using namespace std;// a predicate implemented as a function:bool single_digit (const int& value) { return (value<10); }// a predicate implemented as a class:class is_odd{public:  bool operator() (const int& value) {return (value%2)==1; }};int main (){  int myints[]= {15,36,7,17,20,39,4,1};  list<int> mylist (myints,myints+8);   // 15 36 7 17 20 39 4 1  mylist.remove_if (single_digit);      // 15 36 17 20 39  mylist.remove_if (is_odd());          // 36 20  cout << "mylist contains:";  for (list<int>::iterator it=mylist.begin(); it!=mylist.end(); ++it)    cout << " " << *it;  cout << endl;  return 0;}
[解决办法]
指定要移除哪个值的判定函数.
该函数返回值为bool类型.用于指定哪个值是要删除的.
[解决办法]
++
探讨
C/C++ code
#include <iostream>
#include <list>
using namespace std;

// a predicate implemented as a function:
bool single_digit (const int&amp; value) { return (value<10); }

// a predicate i……

[解决办法]
template <class T>
class functor
{
public:
bool operator() (T* rhs){return true, //if match your condition, false if dont}
}
remove_if(con.begin(), con.end(), functor);

热点排行