I am attempting to write data to a file from a while loop and then read the file back to the output screen. All three loops write to the file BUT it is only the last loop that reads back to the output screen (three times). Here is what I have written, maybe you can tell me where I am going wrong:
using namespace std;
There are a couple of errors that stand out above.
1. the file is closed inside the while loop. That means it's guaranteed to fail on the second iteration, regardless of the status of eof() - which has no sensible meaning for a file which is closed.
2. The data is written out in writeFile() with each value separated by a newline.
It should therefore be read back a whole line at a time. Otherwise problems will arise if any of title, artist or genre consists of more than a single word.