#include "Employee.h" #include "Person.h" #include #include #include #include // header for file streams #include // include headers that implement a archive in simple text format #include #include // include header that allows serialization of STL list #include #include BOOST_CLASS_EXPORT_GUID(Employee, "Employee") // STL collection of Person* std::list people; void add(Person *newP) { // creates a person, collects the information, adds person to list newP->askForInfo(); people.push_back(newP); } void showPerson(Person *p) { // displays a person p->display(); } void display() { // displays all the people std::for_each(people.begin(), people.end(), &showPerson); } int main() { // deserialize existing file (if there is one) try { // create and open an archive for input std::ifstream ifs("file.dat"); boost::archive::text_iarchive ia(ifs); // read class state from archive ia >> people; // archive and stream closed when destructors are called } catch (...) { } char choice = 0; while (choice != 'X') { switch (choice) { case 'P': add(new Person()); break; case 'E': add(new Employee()); break; case 'D': display(); break; } std::cout << "Enter choice: Add [P]erson, add [E]mployee, [D]isplay, e[X]it: "; std::cin >> choice; choice = std::toupper(choice); } // save data to archive std::ofstream ofs("file.dat"); boost::archive::text_oarchive oa(ofs); oa << people; // archive and stream closed when destructors are called return 0; }