// STL2.cp #include #include #include #include int main() { std::vector v; assert(v.empty()); v.push_back("sleep"); v.insert(v.end(), "was"); assert(v.size() == 2); v.push_back("for"); v.push_back("the"); v.push_back("weak"); v.push_back("or"); v.pop_back(); v.push_back("and"); v.push_back("sickly"); v[1] = "is"; // Used to replace existing: "is" for "was" // v[7] = "DOS users"; // Cannot use this notation to add elements. std::vector::iterator vi; for (vi = v.begin(); vi != v.end(); ++vi) { std::cout << (*vi) << " "; } std::cout << std::endl; typedef std::deque MyDeque; MyDeque d((v.begin()), (v.end())); d.erase(d.end() - 3, d.end() - 1); d.push_front("MacHack:"); std::ostream_iteratorout(std::cout, " "); std::copy(d.begin(), d.end(), out); std::cout << std::endl; } // sleep is for the weak and sickly // MacHack: sleep is for the sickly