vector‹char*›::iterator i;
for (i = names.begin(); i!= names.end(); i++) cout ‹‹ *i ‹‹ endl;
return 0;
}
finsert2.cpp
#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;
}
mset2.cpp
#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;
}
ostmit.cpp
#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;
}
ptrunf1.cpp
#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;
}
func1.cpp
#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;
}