reading until the end of file in C++

后端 未结 2 1244
Happy的楠姐
Happy的楠姐 2020-12-17 04:19

I\'m trying to read till the end of a file for a phonebook app that im converting from C to C++. When I print the the results from the file i get this:

johnn         


        
2条回答
  •  难免孤独
    2020-12-17 04:39

    Do not use eof() to determine if you reached end of file. Instead, read what you want to read and then check if you successfully read the data. Obce reading failed you may use eof() to determine if the error is down to having reached the end of the file before producing an error report about a format error.

    Since you mentioned that you read that using !infile.eof() is good practice: Can you point us at the source of this wrong information? This information need correction.

提交回复
热议问题