Reputation: 11
the fstream and string inlcusions are in the .h file. I've read multiple people's problems but can't seem to apply it to my own. I've tried putting in infile.getfile(dataFile, line)) to no avail. The dataFile is just a list of employees. I still keep getting the same no instance of overloaded function with getfile(dataFile, line)
{
ifstream infile;
infile.open(dataFile);
if(!infile.good())
{
cout << "File is not open";
}
else
{
int i = 0;
while(!infile.good())
{
string line;
while (getline(dataFile, line))
{
if (line[0] == 'h' )
{
HospitalEmployee newEmp;
}
}
}
}
}
Upvotes: 1
Views: 14876
Reputation: 385098
Your infile.open(dataFile)
suggests that dataFile
is the string filename and infile
is the stream.
So, instead of getline(dataFile, line)
, you mean getline(infile, line)
.
Typo, I'm sure.
Upvotes: 1
Reputation: 96790
while (getline(dataFile, line))
The first argument is the stream, and the second argument is the string where the line will be assigned. You got the second argument right, but the first argument is a string
object, not the file stream from which the line will be extracted. You're supposed to pass the stream, inFile
:
while (getline(inFile, line))
// ^^^^^^
Upvotes: 3