I have to write a program where it takes in data of name, id, rate, and hours. I have to use an array of struct or this. I am unclear on how I should use ifstream to store the array of struct. Please help, I'm new to this. This is what I was trying to do so far. There is more to this program but I just need some guidance on this part. It is not done as I cant figure it out. THanks
#include <iostream>
#include <string>
#include <fstream>
struct P
{
std::string employeeName;
double employeeID;
double rate;
double hours; // Think about it, wouldn't it be more logical if employees can work half hours or something?
// A data type that can store decimals is better.
};
bool read_txt_file(P p[], constint arraySize)
{
std::ifstream myFile("Project3.txt");
if(!myFile)
{
std::cerr << "Error: Unable to open file.\n";
returnfalse;
}
else
{
while(!myFile.eof())
{
// what can you do here if the end of file hasn't been reached?
// (hint: you're going to be reading value from the file here)
}
}
}
int main()
{
constint arraySize = 5;
P p[arraySize];
if(read_txt_file(p, arraySize))
{
std::cout << "Function returned true" << std::endl;
}
return 0;
}