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:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
Thanks agian for the quick reponse. Below is what I have now. I am still getting the original output but all three loops are writing to the file. Can you advise me how to correct the inFile to read the entire document, rather than just the first three lines? Thanks so much again.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
May I ask, when you share your code, please use the code tags, using the <> button from the format options on the right. Like this [code]your code here[/code].
Reading from the file is going to be very similar in structure to the way it was created. That is:
open the file for input
read and display all of the data
close the file.
The difference is, we originally used a loop to output exactly three songs. When reading from the file, it's best to assume that there is an unknown quantity of songs. So we will just keep reading/displaying until there is no more data.
Hence we need something like this: