}
int input1[4] = {7, 2, 3, 5};
int input2[4] = {1, 5, 5, 8};
int main() {
int output[4];
transform(input1, input1 + 4, input2, output, pointer_to_binary_function‹int, int, int›(sum));
for (int i = 0; i ‹ 4; i++) cout ‹‹ output[i] ‹‹ endl;
return 0;
}
iter2.cpp
#include ‹iostream.h›
#include ‹stl.h›
void print (const vector‹const char*›& v_) {
vector‹const char*›::const_iterator i;
for (i = v_.begin(); i != v_.end(); i++) cout ‹‹ *i ‹‹ endl;
}
int main() {
vector‹const char*› v; // Vector of character strings.
v.push_back((char*) 'zippy');
v.push_back((char*) 'motorboy');
print (v);
return 0;
}
partsum1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main() {
vector‹int› v1(10);
iota(v1.begin(), v1.end(), 0);
vector‹int› v2(v1.size());
partial_sum(v1.begin(), v1.end(), v2.begin());
ostream_iterator ‹int› iter(cout, ' ');
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
copy(v2.begin(), v2.end(), iter);
cout ‹‹ endl;
return 0;
}
replif1.cpp
#include ‹stl.h›
#include ‹iostream.h›
bool odd(int a_) {
return a_ % 2;
}
int main() {
vector‹int› v1(10);
for (int i = 0; i ‹ v1.size(); i++) {
v1[i] = i % 5;
cout ‹‹ v1[i] ‹‹ ' ';
}
cout ‹‹ endl;
replace_if(v1.begin(), v1.end(), odd, 42);
for (i = 0; i ‹ v1.size(); i++) cout ‹‹ v1[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
mset4.cpp
#include ‹iostream.h›
#include ‹stl.h›
int array[] = {3, 6, 1, 2, 3, 2, 6, 7, 9};
int main()
{
typedef multiset‹int, less‹int› › mset;
mset s(array, array + 9);
pair‹mset::const_iterator, mset::const_iterator› p = s.equal_range(3);
cout ‹‹ 'lower bound = ' ‹‹ *(p.first) ‹‹ endl;
cout ‹‹ 'upper bound = ' ‹‹ *(p.second) ‹‹ endl;
return 0;
}
iter3.cpp