Question
Can you help me figure out why my code is not working? #include #include #include #include // Structure to represent an employee struct Employee
Can you help me figure out why my code is not working?
#include
#include
#include
#include
// Structure to represent an employee
struct Employee {
int id;
std::string firstName;
std::string lastName;
std::string phoneNumber;
std::string emailAddress;
double salary;
// Constructor for easy initialization
Employee(int empId, const std::string& first, const std::string& last,
const std::string& phone, const std::string& email, double empSalary)
: id(empId), firstName(first), lastName(last), phoneNumber(phone),
emailAddress(email), salary(empSalary) {}
};
int main() {
// Create a list to store employee data
std::list
// Open the file for reading
std::ifstream inputFile("employeeDataset.txt");
if (!inputFile.is_open()) {
std::cerr<<"Error opening the file.\n";
return 1;
}
// Read data from the file and populate the list
int id;
std::string firstName, lastName, phoneNumber, emailAddress;
double salary;
while (inputFile>>id>>firstName>>lastName>>phoneNumber>>emailAddress>>salary) {
employeeList.push_back(Employee(id, firstName, lastName, phoneNumber, emailAddress, salary));
}
// Close the file
inputFile.close();
// Displaying employee data from the list
std::cout<<"Employee List:\n";
std::cout<<"=======================================================================\n";
std::cout<<"| ID | First Name | Last Name | Phone | Email | Salary |\n";
std::cout <<"=======================================================================\n";
for(const auto& emp : employeeList) { std::cout<<"=======================================================================\n"; return 0;
std::cout<<"|"<
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started