ostream_iterator‹int› iter(cout, ' ');
copy(v2.begin(), v2.end(), iter);
cout ‹‹ endl;
return 0;
}
ptrbinf2.cpp
#include ‹iostream.h›
#include ‹stl.h›
int sum(int x_, int y_) {
return x_ + y_;
}
int input1[4] = {7, 2, 3, 5};
int input2[4] = {1, 5, 5, 8};
int main() {
int output[4];
transform(input1, input1 + 4, input2, output, ptr_fun(sum));
for (int i = 0; i ‹ 4; i++) cout ‹‹ output[i] ‹‹ endl;
return 0;
}
copyb0.cpp
#include ‹stl.h›
#include ‹iostream.h›
int numbers[5] = {1, 2, 3, 4, 5};
int main() {
int result[5];
copy_backward(numbers, numbers + 5, result + 5);
for (int i = 0; i ‹ 5; i++) cout ‹‹ numbers[i] ‹‹ ' ';
cout ‹‹ endl;
for (i = 0; i ‹ 5; i++) cout ‹‹ result[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
binsert1.cpp
#include ‹iostream.h›
#include ‹stl.h›
char* array[] = {'laurie', 'jennifer', 'leisa'};
int main() {
vector‹char*› names;
copy(array, array + 3, back_insert_iterator‹vector‹char*› ›(names));
vector‹char*›::iterator i;
for (i = names.begin(); i!= names.end(); i++) cout ‹‹ *i ‹‹ endl;
return 0;
}
unegate2.cpp
#include ‹iostream.h›
#include ‹stl.h›
struct odd: public unary_function‹int, bool› {
odd() {}
bool operator() (int n_) const {return (n_ % 2) - 1;}
};
int array[3] = {1, 2, 3};
int main() {
int* p = find_if(array, array + 3, not1 (odd()));
if (p != array + 3) cout ‹‹ *p ‹‹ endl;
return 0;
}
revcopy1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int numbers[6] = {0, 1, 2, 3, 4, 5};
int main() {
int result[6];
reverse_copy(numbers, numbers + 6, result);
for (int i = 0; i ‹ 6; i++) cout ‹‹ numbers[i] ‹‹ ' ';
cout ‹‹ endl;
for (i = 0; i ‹ 6; i++) cout ‹‹ result[i] ‹‹ ' ';
cout ‹‹ endl;