uprbnd1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main() {
int array[20];
for (int i = 0; i ‹ 20; i++) {
array[i] = i/4;
cout ‹‹ array[i] ‹‹ ' ';
}
cout ‹‹ '
3 can be inserted at index: '
‹‹ upper_bound(array, array + 20, 3) - array ‹‹ endl;
return 0;
}
equalto.cpp
#include ‹iostream.h›
#include ‹stl.h›
int input1[4] = {1, 7, 2, 2};
int input2[4] = {1, 6, 2, 3};
int main() {
int output[4];
transform(input1, input1 + 4, input2, output, equal_to‹int›());
for (int i = 0; i ‹ 4; i++) cout ‹‹ output[i] ‹‹ endl;
return 0;
}
count1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main() {
vector‹int› numbers(100);
for (int i = 0; i ‹ 100; i++) numbers[i] = i % 3;
int elements = 0;
count(numbers.begin(), numbers.end(), 2, elements);
cout ‹‹ 'Found ' ‹‹ elements ‹‹ ' 2's.' ‹‹ endl;
return 0;
}
uniqcpy1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int numbers[8] = {0, 1, 1, 2, 2, 2, 3, 4};
int result[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int main() {
unique_copy(numbers, numbers + 8, result);
for (int i = 0; i ‹ 8; i++) cout ‹‹ result[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
minus.cpp
#include ‹iostream.h›
#include ‹stl.h›
int input1[4] = {1, 5, 7, 8};
int input2[4] = {1, 4, 8, 3};
int main() {
int output[4];
transform(input1, input1 + 4, input2, output, minus‹int›());
for (int i = 0; i ‹ 4; i++) cout ‹‹ output[i] ‹‹ endl;
return 0;
}
replcpy1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int numbers[6] = {0, 1, 2, 0, 1, 2};
int result[6] = {0, 0, 0, 0, 0, 0};
int main() {
replace_copy(numbers, numbers + 6, result, 2, 42);
for (int i = 0; i ‹ 6; i++) cout ‹‹ result[i] ‹‹ ' ';