Wrong logic, I would say. I think you want:
Try to open an ifstream (not an fstream) containing scores
if it opened
read high scores into array
close stream
else
set array to zero
endif
Play Game - adjust high scores in array, then on exit
Try to open scores ofstream (not an fstream) for writing
if it opened
write high scores
close stream
else
report an error
end if
If you use ifstream and streamstream, there is no need for special flags or, perhaps, a search in the file - you just rewrite all of this.
anon
source
share