STL_Algorithm3: remove, remove_if, remove_copy, remove_copy_if
来源:互联网 发布:怎样经营好一家淘宝店 编辑:程序博客网 时间:2024/06/03 02:40
// Remove.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
using std::cout;
using std::endl;
bool greater9( int );
int main()
{
const int SIZE = 10;
int a[SIZE] = { 10, 2, 10, 4, 16, 6, 14, 8, 12, 10 };
std::ostream_iterator< int > outputIt( cout, " " );
std::vector< int > v( a, a + SIZE );
std::vector< int >::iterator newLastElement;
cout<<"Vector v before removing all 10s: /n ";
std::copy( v.begin(), v.end(), outputIt );
newLastElement = std::remove( v.begin(), v.end(), 10 );
cout<<"/nVector v after removing all 10s: /n ";
std::copy( v.begin(), v.end(), outputIt );
std::vector< int > v2( a, a + SIZE );
std::vector< int > c( SIZE, 0 );
cout<<"/n/nVector v2 before removing all 10s and copying:/n";
std::copy( v2.begin(), v2.end(), outputIt );
std::remove_copy( v2.begin(), v2.end(), c.begin(), 10 );
cout<<"/nVector c after remvoing all 10s from v2:/n ";
std::copy( c.begin(), c.end(), outputIt );
std::vector< int > v3( a, a + SIZE );
cout<<"/n/nVector v3 before removing all elements"
<<"/nfreater than 9:/n";
std::copy( v3.begin(), v3.end(), outputIt );
newLastElement = std::remove_if( v3.begin(), v3.end(), greater9 );
cout<<"/nVector v3 after removing all elements"
<<"/ngreater than 9:/n";
std::copy( v3.begin(), newLastElement, outputIt );
std::vector< int > v4( a, a + SIZE );
std::vector< int > c2( SIZE, 0 );
cout<<"/n/nVector v4 before removing all elements"
<< "/ngreater than 9 and copying:/n";
std::copy( v4.begin(), v4.end(), outputIt );
std::remove_copy_if( v4.begin(), v4.end(), c2.begin(), greater9 );
cout<<"/nVector c2 after removing all elements"
<< "/ngreater than 9 from v4:/n";
std::copy( c2.begin(), c2.end(), outputIt );
cout<<endl;
return 0;
}
bool greater9( int x )
{
return x > 9;
}
- STL_Algorithm3: remove, remove_if, remove_copy, remove_copy_if
- STL 之remove,remove_if,remove_copy,remove_copy_if
- STL 之remove,remove_if,remove_copy,remove_copy_if
- STL之remove、remove_copy、remove_if、remove_copy_if
- remov,remove_if,remove_copy,remove_copy_if
- STL_算法_删除(remove、remove_if、remove_copy、remove_copy_if)
- STL常用算法: remove,remove_if,remove_copy,remove_copy_if,remove系列算法和partition的区别...
- 变异算法之删除(remove, remove_if, remove_copy, remove_copy)
- remove_copy/remove_copy_if详解
- STL算法之—————remove_if, remove, remove_copy_if
- [C/C++]_[初级]_[使用remove,remove_if,remove_copy_if过滤元素或字符]
- STL algorithm算法remove_copy,remove_copy_if(48)
- remove remove_if
- 泛型算法系列19:remove_if()&&remove_copy_if()
- remove和remove_copy
- C++ STL 算法:删除算法(2)remove_copy、remove_copy_if
- C++ remove,remove_if
- STL remove和remove_if
- 成员函数指针与高性能的C++委托(上篇)
- 10 12 23 就一个人
- ArcGIS Desktop 10新特性(七)
- STL_Algorithm2: equal, mismatch, lexicographical_compare
- 使用原子操作同步队列
- STL_Algorithm3: remove, remove_if, remove_copy, remove_copy_if
- 操作系统第七章-存储器管理
- 域名的概念与机制
- C语言编程经验总结
- GVIM/VIM 拦截到致命信号(deadly signa) SEGV 解决方法
- CSpinButtonCtrl控件的使用方法
- 我第一个用DirextX做的2D游戏——炮炮兵考眼力
- DNS(域名服务器)欺骗技术
- 最近很是紧张,希望自己能及时调整过来。。。。