remove_copy_If()的作用是用于拷贝自己想要类型的值到另外一个容器或者覆盖自身
remove_copy_If()需要用到容器开头,结束,拷贝容器的开头,拷贝条件。
例子代码如下:
//有效值获取复制
bool bools(int i) {
//取一个值能被二整除的值
return ((i % 2) == 1);
}
void RemoveCopyIf()
{
//旧容器
int myattr[] = { 1,2,4,3,8,9,7,5,6,10 };
//创建一个新容器
vector<int> myattring(10);
//将myattr里符合条件的数据拷贝到myattring中
remove_copy_if(myattr, myattr + 10, myattring.begin(), bools);
//用作对比比较
cout << "1 2 4 3 8 9 7 5 6 10" << endl;
cout << endl;
//for循环遍历出所有拷贝值
for (vector<int>::iterator it = myattring.begin(); it != myattring.end(); ++it)
{
cout << *it << ends;
}
}
void main(){
RemoveCopyIf();
}
效果如下: