topical media & game development
professional-program-23-IteratorAdapters-BackInsertIterator.c
? /
professional-program-23-IteratorAdapters-BackInsertIterator.c
include <algorithm>
include <functional>
include <iterator>
include <vector>
include <iostream>
using namespace std;
// Function template to populate a container of ints.
// The container must support push_back().
template<typename Container>
void populateContainer(Container& cont)
{
int num;
while (true) {
cout << "Enter a number (0 to quit): ";
cin >> num;
if (num == 0) {
break;
}
cont.push_back(num);
}
}
int main(int argc, char** argv)
{
vector<int> vectorOne, vectorTwo;
populateContainer(vectorOne);
back_insert_iterator<vector<int> > inserter(vectorTwo);
remove_copy_if(vectorOne.begin(), vectorOne.end(), inserter,
bind2nd(equal_to<int>(), 100));
copy(vectorTwo.begin(), vectorTwo.end(), ostream_iterator<int>(cout, " "));
cout << endl;
return (0);
}
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.