Шрифт:
ostream_iterator‹int› iter(cout, " ");
copy(v1.begin, v1.end, iter);
cout ‹‹ endl;
copy(v2.begin, v2.end, iter);
cout ‹‹ endl;
return 0;
}
istmit1.cpp
#include ‹iostream.h›
#include ‹stl.h›
int main {
char buffer[100];
int i = 0;
cin.unsetf(ios::skipws); // Disable white-space skipping.
cout ‹‹ "Please enter a string: ";
istream_iterator‹char, ptrdiff_t› s(cin);
while (*s!= '\n') buffer[i++] = *s++;
buffer[i] = '\0'; // Null terminate buffer.
cout ‹‹ "read " ‹‹ buffer ‹‹ endl;
return 0;
}
findif0.cpp
#include ‹stl.h›
#include ‹iostream.h›
bool odd(int a_) {
return a_ % 2;
}
int numbers[6] = {2, 4, 8, 15, 32, 64};
int main {
int* location = find_if(numbers, numbers + 6, odd);
if (location != numbers + 6)
cout ‹‹ "Value " ‹‹ *location ‹‹ " at offset " ‹‹ (location - numbers) ‹‹ " is odd" ‹‹ endl;
return 0;
}
pheap1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main {
vector‹int› v;
v.push_back(1);
v.push_back(20);
v.push_back(4);
make_heap(v.begin, v.end);
v.push_back(7);
push_heap(v.begin, v.end);
sort_heap(v.begin, v.end);
ostream_iterator‹int› iter(cout, " ");
copy(v.begin, v.end, iter);
cout ‹‹ endl;
return 0;
}
stblsrt2.cpp
#include ‹stl.h›
#include ‹iostream.h›
#include ‹string.h›
bool string_less(const char* a_, const char* b_) {
return ::strcmp(a_, b_) ‹ 0 ? 1 : 0;
}
char* letters[6] = {"bb", "aa", "ll", "dd", "qq", "cc"};
int main {
stable_sort(letters, letters + 6, string_less);
for (int i = 0; i ‹ 6; i++) cout ‹‹ letters[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
nextprm1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main {
vector‹int› v1(3);
iota(v1.begin, v1.end, 0);
ostream_iterator‹int› iter(cout, " ");
copy(v1.begin, v1.end, iter);
cout ‹‹ endl;
for (int i = 0; i ‹ 9; i++) {
next_permutation(v1.begin, v1.end);
copy(v1.begin, v1.end, iter);
cout ‹‹ endl;
}
return 0;
}
prevprm1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main {
vector‹int› v1(3);
iota(v1.begin, v1.end, 0);
ostream_iterator‹int› iter(cout, " ");