copy(result.begin(), result.end(), iter);
cout ‹‹ endl;
return 0;
}
stblptn1.cpp
#include ‹stl.h›
#include ‹stdlib.h›
#include ‹iostream.h›
int main() {
vector‹int› v1(10);
for (int i = 0; i ‹ v1.size(); i++) v1[i] = rand() % 20;
ostream_iterator‹int› iter(cout, " ");
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
stable_partition(v1.begin(), v1.end(), bind2nd(less‹int›(), 11));
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
return 0;
}
ptition1.cpp
#include ‹stl.h›
#include ‹stdlib.h›
#include ‹iostream.h›
int main() {
vector‹int› v1(10);
for (int i = 0; i ‹ v1.size(); i++) v1[i] = rand() % 20;
ostream_iterator ‹int› iter(cout, " ");
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
partition(v1.begin(), v1.end(), bind2nd(less‹int›(), 11));
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
return 0;
}
vec1.cpp
#include ‹iostream.h›
#include ‹stl.h›
int main() {
vector‹int› v1; // Empty vector of integers.
cout ‹‹ "empty = " ‹‹ v1.empty() ‹‹ endl;
cout ‹‹ "size = " ‹‹ v1.size() ‹‹ endl;
cout ‹‹ "max_size = " ‹‹ v1.max_size() ‹‹ endl;
v1.push_back(42); // Add an integer to the vector.
cout ‹‹ "size = " ‹‹ v1.size() ‹‹ endl;
cout ‹‹ "v1[0] = " ‹‹ v1[0] ‹‹ endl;
return 0;
}
sort2.cpp
#include ‹stl.h›
#include ‹iostream.h›
int array[] = {1, 50, -10, 11, 42, 19};
int main() {
int count = sizeof(array) / sizeof(array[0]);
ostream_iterator ‹int› iter(cout, " ");
cout ‹‹ "before: ";
copy(array, array + count, iter);
cout ‹‹ "\nafter: ";
sort(array, array + count, greater‹int›());
copy(array, array + count, iter);
cout ‹‹ endl;
return 0;
}
copy4.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main() {
typedef vector‹int› IVec;
vector‹int› v1(10);
for (int loc = 0; loc ‹ v1.size(); loc++) v1[loc] = loc;
vector‹int› v2;
insert_iterator‹IVec› i (v2, v2.begin());
copy(v1.begin(), v1.end(), i);
ostream_iterator‹int› outiter(cout, " ");
copy(v2.begin(), v2.end(), outIter);
cout ‹‹ endl;
return 0;
}
prevprm2.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++) {
prev_permutation(v1.begin(), v1.end(), greater‹int›());
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
}
return 0;
}
trnsfrm2.cpp
#include ‹stl.h›
#include ‹iostream.h›
#include ‹string.h›
char map_char(char a_, int b_) {
return char(a_ + b_);
}
int trans[] = {-4, 4, -6, -6, -10, 0, 10, -6, 6, 0, -1, -77};
char n[] = "Larry Mullen";
int main() {
const unsigned count = ::strlen(n);
ostream_iterator ‹char› iter(cout);