#include #include #include #include #include #include #include using namespace std; void main() { char text[] = "STL is an abbreviation of Standard Template Library"; vector v(&text[0], &text[strlen(text)]); // construct vector as copy of text // partition divides v into the elements that satisfy isupper() and those that don't. // the return value is a bidirectional iterator to the position of division and since v_iter is // a random access iterator, assignment is OK. vector::iterator v_iter = partition(v.begin(), v.end(), isupper); list l(v_iter, v.end()); // construct l by passing it random access iterators to range of lowercase chars // adjacent_find returns forward iterator to the beginning of the first occurrence of two adjacent elements. // l_iter is a bidirectional iterator so assignment is OK. list::iterator l_iter = adjacent_find(l.begin(), l.end()); multiset s; // transforms expects two input iterators and an output iterator as its first three arguments, so // any container, including list and set, can be used with it. transform(l_iter, l.end(), inserter(s, s.begin()), toupper); // convert to upper case and insert into s // remove accepts forward iterators as its first two arguments so set is more than fully qualified // erase accepts bidirectional iterators, of course, since it is a set member function s.erase(remove(s.begin(), s.end(), ' '), s.end()); // remove spaces // copy expects 2 input iterators as its first two arguments and so any container, including set, can // be used in a call to it. copy(s.begin(), s.end(), ostream_iterator(cout, " ")); }