Main
unknown
c_cpp
2 months ago
1.4 kB
2
Indexable
#include <iostream> #include <fstream> #include <stdexcept> #include <memory> #include "Employee.h" using namespace std; int main(int argc, char* argv[]) { // Check if a filename was provided as a command-line argument if (argc != 2) { std::cerr << "Usage: " << argv[0] << " <XMLFile>" << std::endl; return 1; } const std::string filename = argv[1]; // Open the XML file for reading std::ifstream xmlFile(filename); if (!xmlFile) { std::cerr << "Error: Could not open file " << filename << std::endl; return 1; } else { Employee* employee; try { // Read the XML and create the Employee from XML std::cout << "Employee successfully loaded from XML:" << std::endl; while ((employee = Employee::fromXML(xmlFile)) != nullptr) { cout << "Parsing employee\n"; employee->display(std::cout); // Display the employee information cout << endl; } // Output the Employee object as XML again (for validation) employee->display(std::cout); } catch (const std::runtime_error& e) { // Catch and display any runtime errors (e.g., XML parsing errors) std::cerr << "Error: " << e.what() << std::endl; return 1; } } return 0; }
Editor is loading...
Leave a Comment