ostream_iterator‹int› iter(cout, ' ');
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
return 0;
}
remif1.cpp
#include ‹stl.h›
#include ‹iostream.h›
bool odd(int a_) {
return a_ % 2;
}
int numbers[6] = {0, 0, 1, 1, 2, 2};
int main() {
remove_if(numbers, numbers + 6, odd);
for (int i = 0; i ‹ 6; i++)
cout ‹‹ numbers[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
foreach1.cpp
#include ‹stl.h›
#include ‹iostream.h›
void print_sqr(int a_) {
cout ‹‹ a_ * a_ ‹‹ ' ';
}
int main() {
vector‹int› v1(10);
for (int i = 0; i ‹ v1.size(); i++) v1[i] = i;
for_each(v1.begin(), v1.end(), print_sqr);
cout ‹‹ endl;
return 0;
}
parsrtc0.cpp
#include ‹stl.h›
#include ‹iostream.h›
int numbers[6] = {5, 2, 4, 3, 1, 6};
int main() {
int result[3];
partial_sort_copy(numbers, numbers + 6, result, result + 3);
for (int i = 0; i ‹ 3; i++) cout ‹‹ result[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
pqueue2.cpp
#include ‹iostream.h›
#include ‹stl.h›
int main() {
priority_queue‹deque‹char*›, greater_s› q;
q.push((char*) 'cat');
q.push((char*) 'dog');
q.push((char*) 'ape');
while (!q.empty()) {
cout ‹‹ q.top() ‹‹ endl;
q.pop();
}
return 0;
}
binsrch1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main() {
int vector[100];
for (int i = 0; i ‹ 100; i++) vector[i] = i;
if (binary_search(vector, vector + 100, 42)) cout ‹‹ 'found 42' ‹‹ endl;
else cout ‹‹ 'did not find 42' ‹‹ endl;
return 0;
}