count0.cpp
#include ‹stl.h›
#include ‹iostream.h›
int numbers[10] = {1, 2, 4, 1, 2, 4, 1, 2, 4, 1};
int main() {
int result = 0;
count(numbers, numbers + 10, 1, result);
cout ‹‹ 'Found ' ‹‹ result ‹‹ ' 1's.' ‹‹ endl;
return 0;
}
negate.cpp
#include ‹iostream.h›
#include ‹stl.h›
int input[3] = {1, 2, 3};
int main() {
int output[3];
transform(input, input + 3, output, negate‹int›());
for (int i = 0; i ‹ 3; i++) cout ‹‹ output[i] ‹‹ endl;
return 0;
}
pqueue1.cpp
#include ‹iostream.h›
#include ‹stl.h›
int main() {
priority_queue‹deque‹int›, less‹int› › q;
q.push(42);
q.push(101);
q.push(69);
while (!q.empty()) {
cout ‹‹ q.top() ‹‹ endl;
q.pop();
}
return 0;
}
genern1.cpp
#include ‹stl.h›
#include ‹iostream.h›
#include ‹stdlib.h›
int main() {
vector‹int› v1(10);
generate_n(v1.begin(), v1.size(), rand);
for (int i = 0; i ‹ 10; i++) cout ‹‹ v1[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
rotate0.cpp
#include ‹stl.h›
#include ‹iostream.h›
int numbers[6] = {0, 1, 2, 3, 4, 5};
int main() {
rotate(numbers, numbers + 3, numbers + 6);
for (int i = 0; i ‹ 6; i++) cout ‹‹ numbers[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
foreach0.cpp
#include ‹stl.h›
#include ‹iostream.h›
void print(int a_) {
cout ‹‹ a_ ‹‹ ' ';
}
int numbers[10] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55};
int main() {
for_each(numbers, numbers + 10, print);
cout ‹‹ endl;
return 0;
}