现在的位置: 首页 > 综合 > 正文

remove_if http://www.cplusplus.com/reference/algorithm/remove_if/

2012年09月11日 ⁄ 综合 ⁄ 共 378字 ⁄ 字号 评论关闭
// remove_if example
#include <iostream>
#include
<algorithm>
using namespace std;

bool IsOdd (int i) { return ((i%2)==1); }

int main () {
int myints[] = {1,2,3,4,5,6,7,8,9}; // 1 2 3 4 5 6 7 8 9

// bounds of range:
int* pbegin = myints; // ^
int* pend = myints+sizeof(myints)/sizeof(int); // ^ ^

pend
= remove_if (pbegin, pend, IsOdd); // 2 4 6 8 ? ? ? ? ?
// ^ ^
cout << "range contains:";
for (int* p=pbegin; p!=pend; ++p)
cout
<< " " << *p;

cout
<< endl;

return 0;
}

抱歉!评论已关闭.