cout ‹‹ endl;
return 0;
}
#include ‹iostream.h›
#include ‹stl.h›
int array[] = {1, 5, 2, 3};
int main() {
list‹int› v(array, array + 4);
reverse_bidirectional_iterator‹list‹int›::iterator, int, list‹int›::reference, list‹int›::difference_type› r(v.end());
while (r != v.begin())
cout ‹‹ *r++ ‹‹ endl;
return 0;
}
#include ‹stl.h›
#include ‹iostream.h›
int main() {
vector‹int› v1(10);
for (int i = 0; i ‹ v1.size(); i++) v1[i] = i;
vector‹int› v2(10);
copy(v1.begin(), v1.end(), v2.begin());
ostream_iterator‹int› iter(cout, " ");
copy(v2.begin(), v2.end(), iter);
cout ‹‹ endl;
return 0;
}
#include ‹stl.h›
#include ‹iostream.h›
int numbers1[5] = {1, 6, 13, 25, 101};
int numbers2[5] = {-5, 26, 36, 46, 99};
int main() {
int result[10];
merge(numbers1, numbers1 + 5, numbers2, numbers2 + 5, result);
for (int i = 0; i ‹ 10; i++) cout ‹‹ result[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
#include ‹iostream.h›
#include ‹stl.h›
int array[] = {1, 5, 2, 3};
int main() {
vector‹int› v(array, array + 4);
stl_reverse_iterator‹vector‹int›::iterator, int, vector‹int›::reference, vector‹int›::difference_type› r (v.end());
while (r!= v.begin()) cout ‹‹ *r++ ‹‹ endl;
return 0;
}
#include ‹stl.h›
#include ‹iostream.h›
int years[] = {1942, 1952, 1962, 1972, 1982, 1992};
int main() {
const unsigned yearCount = sizeof(years) / sizeof(years[0]);
int* location = find(years, years + yearCount, 1972);
cout ‹‹ "Found 1972 at offset " ‹‹ (location - years) ‹‹ endl;
return 0;
}
#include ‹stl.h›
#include ‹iostream.h›
int negate_int(int a_) {
return -a_;
}
int numbers[6] = {-5, -1, 0, 1, 6, 11};
int main() {
int result[6];
transform(numbers, numbers + 6, result, negate_int);
for (int i = 0; i ‹ 6; i++) cout ‹‹ result[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
#include ‹iostream.h›
#include ‹stl.h›
char* array[] = {"laurie", "jennifer", "leisa"};
int main() {
vector‹char*› names;
copy(array, array + 3, back_inserter(names));
vector‹char*›::iterator i;
for (i = names.begin(); i!= names.end(); i++) cout ‹‹ *i ‹‹ endl;
return 0;
}
#include ‹iostream.h›
#include ‹stl.h›
char* array[] = {"laurie", "jennifer", "leisa"};
int main() {
deque‹char*› names;
copy(array, array + 3, front_inserter(names));
deque‹char*›::iterator i;
for (i = names.begin(); i!= names.end(); i++) cout ‹‹ *i ‹‹ endl;
return 0;
}
#include ‹iostream.h›
#include ‹stl.h›
char* names[] = {"dave", "alf", "chas", "bob", "ed", "chas"};
int main() {
typedef multiset‹char*, less_s› mset;
mset s;
s.insert(names, names + 6);
for (mset::iterator i = s.begin(); i!= s.end(); i++) cout ‹‹ *i ‹‹ endl;
return 0;
}
#include ‹iostream.h›
#include ‹stl.h›
int array[] = {1, 5, 2, 4};
int main() {
char* string = "hello";
ostream_iterator‹char› it1(cout);
copy(string, string + 5, it1);
cout ‹‹ endl;
ostream_iterator‹int› it2(cout);
copy(array, array + 4, it2);
cout ‹‹ endl;
return 0;
}
#include ‹iostream.h›
#include ‹stl.h›
bool even(int n_) {
return (n_ % 2) == 0;
}
int array[3] = {1, 2, 3};
int main() {
int* p = find_if(array, array + 3, pointer_to_unary_function‹int, bool›(even));
if (p != array + 3) cout ‹‹ *p ‹‹ " is even" ‹‹ endl;
return 0;
}
#include ‹iostream.h›
#include ‹stl.h›
bool bigger(int i_) {
return i_ › 3;
}
int main() {
vector‹int› v;
v.push_back(4);
v.push_back(1);
v.push_back(5);
int n = 0;
count_if(v.begin(), v.end(), bigger, n);
cout ‹‹ "Number greater than 3 = " ‹‹ n ‹‹ endl;
return 0;
}
#include ‹stl.h›
#include ‹iostream.h›
bool less_10(int a_) {
return a_ ‹ 10 ? 1 : 0;
}
int numbers[6] = {10, 5, 11, 20, 6, -2};
int main() {
stable_partition(numbers, numbers + 6, less_10);
for (int i = 0; i ‹ 6; i++) cout ‹‹ numbers[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
#include ‹stl.h›
#include ‹iostream.h›
int v1[3] = {13, 18, 23};
int v2[4] = {10, 13, 17, 23};
int result[7] = {0, 0, 0, 0, 0, 0, 0};
int main() {
set_union(v1, v1 + 3, v2, v2 + 4, result);
for (int i = 0; i ‹ 7; i++) cout ‹‹ result[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
#include ‹stl.h›
#include ‹iostream.h›
Читать дальше