/////////////////////////////////////////////////////////////// // Serial.cpp - demonstrate serialization of STL Containers // // // // Jim Fawcett, CSE687 - Object Oriented Design, Spring 2008 // /////////////////////////////////////////////////////////////// #include #include #include #include #include template typename std::string& operator<<(std::string& temp, const C& c) { std::ostringstream strm; strm << temp; strm << typeid(C).name() << std::endl; strm << typeid(C::value_type).name() << std::endl; C::const_iterator iter; for(iter=c.begin(); iter!=c.end(); ++iter) strm << *iter << std::endl; strm << std::endl; temp = strm.str(); return temp; } void main() { std::cout << "\n Demonstrate Serialization of STL Types - SerialKiller "; std::cout << "\n =======================================================\n\n"; std::string arr[5] = { "aardvark", "chameleon", "platypus", "viper", "zebra" }; std::list ls(arr,arr+5); std::string temp; temp << ls; std::vector vi; vi.push_back(0); vi.push_back(1); vi.push_back(2); temp << vi; std::vector vi2; vi2.push_back(0); vi2.push_back(-1); vi2.push_back(-2); std::list< std::vector > lv; lv.push_back(vi); lv.push_back(vi2); ///////////////////////////////////////////////////////////////// // This does not work. Why not? What will you do about this? // temp << lv; std::cout << temp.c_str() << "\n\n"; }