1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
//STL Function remove, remove_if, removecopy, and remove_copy_if
#include<iostream>
#include<cctype>
#include<algorithm>
#include<iterator>
#include<vector>
using namespace std;
int main() {
int num;
ostream_iterator<int> screen(cout, " ");
int list[10] = {12, 34, 56, 21, 34, 78, 34, 55, 12, 25};
vector<int> intList(list, list + 10);
cout << endl << endl;
copy(intList.begin(), intList.end(), screen);
vector<int> temp(10);
cout <<endl << endl;
replace_copy(intList.begin(), intList.end(), temp.begin(), 34, 0);
copy(temp.begin(), temp.end(), screen);
bool lessThanEqualTo50(int num);
{
return (num <= 50);
}
replace_copy_if(intList.begin(), intList.end(),
temp.begin(), lessThanEqualTo50, 50); cout<< endl;
copy(temp.begin(), temp.end(), screen);
}
|