Reading from a text file (c++)

Started by
11 comments, last by AntonioR 13 years ago

Note this also features more robust error checking. The code you posted fails to close the file, among other issues.

I would not recommend using yewbie's code, it is terrible.


Heh, I am not going to defend what I posted as good code but the tutorial specifically said that when ifstream goes out of scope it cleanly closes the file.
And most of what is posted is directly from the tutorial. ( Edit: not that tutorials are to be trusted )

Much like the OP I only needed it for a couple of config lines and it worked fine for that.
Your code looks much better.
Advertisement

... when ifstream goes out of scope it cleanly closes the file.
[/quote]
That comment was directed at the OP's code, which uses fopen() but fails to call fclose(). I wrote my post before the intermediate comments, and I edited it to include a note about the code you posted, so I can see now why you might think that.
Thanks for the help.

This topic is closed to new replies.

Advertisement