#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;
}
merge0.cpp
#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;
}
reviter1.cpp
#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;
}
find1.cpp
#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;
}
trnsfrm1.cpp
#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;
}
binsert2.cpp
#include ‹iostream.h›
#include ‹stl.h›
char* array[] = {'laurie', 'jennifer', 'leisa'};
int main() {
vector‹char*› names;
copy(array, array + 3, back_inserter(names));