Hello nicholasjb1996,
First off it is hard to tell you how or what you can do to read your file without knowing what this file looks like. I thought of using a string stream, but I do not know what would be there or how to process it.
For line 29:
Do not use the condition of "!infile.eof()". This does not work the way that you are thinking. Usually it will process the last read twice before "eof" is detected. What happens is the last line of the file is read and processed then the while condition is checked and is still not "eof", so the while loop is entered and the next read is done, but there is nothing to read so "eof" is set and nothing is read from the file, but the variables still have the information from the last read and that is processed before the while condition is checked to find "eof" and fails.
A more accepted and better way is:
1 2 3 4
|
while (getline(infile, inContent))
{
cout << inContent << endl;
}
|
This way when "infile" fails "getline" fails and the while condition fails moving on to what is after the while loop.
I do not think I would use the try/catch quite the way you did, but it may still be useful in a different way.
I am think of changing the if statement to
if (!infile.is_open())
and if true print an error message, pause and exit the program because there is nothing else that can be done until the file is opened. Otherwise move on to the rest of the code.
I will load up the program and see if there is anything else wrong.
Hope that helps,
Andy