W
waltbrad
Hello. I'm studying the book "C++ Primer Plus" by Stephan Prata. In
chapter 6 he gives an exercise that reads from a file. The list is
thus:
4
Sam Stone
2000
Freida Flass
100500
Tammy Tubbs
5000
Rich Raptor
55000
So I create a istream object, inFile, and associate the file with
it. I know it reads the file because I've placed cout directives
after every read instruction. (since taken out). But I can't get the
program to read EOF.
After the following code there are conditions that test for
inFile.eof() and inFile.fail() but these get skipped over, to a
default "else" condition.
Can anyone see why EOF is not being recognized?
inFile >> size;
donor *pd = new donor[size];
while(inFile.get() != '\n')
;
for(int i = 0; i < size; i++){
getline(inFile, pd.name); //a cout stmt here and
inFile >> pd.cash; //here lets me know the data was
read
while(inFile.get() != '\n')
;
}
chapter 6 he gives an exercise that reads from a file. The list is
thus:
4
Sam Stone
2000
Freida Flass
100500
Tammy Tubbs
5000
Rich Raptor
55000
So I create a istream object, inFile, and associate the file with
it. I know it reads the file because I've placed cout directives
after every read instruction. (since taken out). But I can't get the
program to read EOF.
After the following code there are conditions that test for
inFile.eof() and inFile.fail() but these get skipped over, to a
default "else" condition.
Can anyone see why EOF is not being recognized?
inFile >> size;
donor *pd = new donor[size];
while(inFile.get() != '\n')
;
for(int i = 0; i < size; i++){
getline(inFile, pd.name); //a cout stmt here and
inFile >> pd.cash; //here lets me know the data was
read
while(inFile.get() != '\n')
;
}