Hi all, I'm trying to open up a .txt file. The file is in the same folder(directory) as my .cpp, and I'm not having any trouble opening the file up. However the .txt file has written in it "Successfully open! Good Job!!". When i run the program it works fine but only "Successfully open! Good" is shown. I've tried changing the value of char filename[50] to 1000, wondering if this would change the amount of characters shown but it didn't. Here is my code, and how do i show everything in the document? Thanks!
Good is set to false because it is no longer a good idea to read from kyle. There is nothing else to read, as you've read the EOF (End of File). If you added one more cout << word << " "; after the loop, it should display "Job!!".
Note: It is more common to use while (!kyle.eof()) {}.
Note: It is more common to use while (!kyle.eof()) {}.
Actually using eof() or good() is a common source of problems. If you forget the pre-read of the first item or place the read in the incorrect place in the loop (the current problem) you will have problems.
Also remember eof() only checks for the eof() condition not for any of the other stream failure mode. So IMO using good() is actually better than using eof() whenever there may be possibilities of failure for one of the other conditions, like a bad data entry.
Lastly IMO it is much easier to just use the read operation to control the loop as shown in my last post. This way there is no need to pre-fetch the first item, nor worry about placing the loop read in the proper place.