#include #include #include #include template < class iter > void view (iter b, iter e) { iter it; for (it = b; it != e; it++) { cout << *it << " "; } cout << "\n"; } #define BE(v) v.begin(), v.end() void action (int a) { cout << a * a << " "; } bool isodd (int a) { if (a % 2) return true; return false; } main () { vector < int >v; v.push_back (3); v.push_back (4); v.push_back (1); view (BE (v)); sort (BE (v)); // sort a vector view (BE (v)); vector < int >::iterator it = lower_bound (BE (v), 2); v.insert (it, 2); view (BE (v)); reverse (BE (v)); // reverse a vector view (BE (v)); for_each (BE (v), action); // do something on each element cout << "\n"; char s[] = "badc"; // sort a string sort (s, s + strlen (s)); cout << s << "\n"; it = remove_if (BE (v), isodd); // odd elements at end view (BE (v)); v.erase (it, v.end ()); // erase them from the end view (BE (v)); }