I am reading a file and storing the data in a vector of a struct type. I have 3 different functions:
- readFile(
insert arg here
) // reads a text file and gets a name and hours worked throughout the week. - bubbleSort(`more arg') // self-explanatory
- output(`arg') // outputs contents of said vector
Function prototypes:
void readFile(vector<Employee *> workers, int numOfEmployees);
void bubbleSort(vector<Employee *> workers, int numOfEmployees);
void output(vector<Employee *> workers, int numOfEmployees);
Struct:
struct Employee
{
string name;
vector<int> hours;
int totalHours;
}
Main:
vector<Employee *> workers;
int numOfEmployees = 0;
readFile(workers, numOfEmployees);
bubbleSort(workers, numOfEmployees);
output(workers, numOfEmployees);
cout << endl;
system("pause");
return 0;
readFile:
ifstream fin;
fin.open("empdata4.txt");
if (fin.fail())
{
cout << "File failed to open. Program will now exit.\n";
exit(1);
}
fin >> numOfEmployees;
workers.resize(numOfEmployees);
for (int row = 0; row < numOfEmployees; row++)
{
workers[row] = new Employee;
workers[row]->hours.resize(7);
fin >> workers[row]->name;
for (int i = 0; i < 7; i++)
{
fin >> workers[row]->hours[i];
}
}
// excluding bubble sort for obvious reasons
output:
for (int i = 0; i < numOfEmployees; i++)
{
cout << workers[i]->name << " ";
for (int x = 0; x < 7; x++)
{
cout << workers[i]->hours[x] << " ";
}
cout << endl;
}
The console output is blank, minus the cout << endl;
in main and system("pause");
I think I set everything up correctly for the most part, but I still don't know. Thanks for any help!
EDIT: Added function prototypes and struct