Microsoft KB Archive/88769

= How To Test for End of File with CFile and CStdioFile =

Article ID: 88769

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 1.51

 Microsoft Visual C++ 1.52 Professional Edition</li></ul>

 Microsoft Visual C++ 1.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 2.2</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q88769

<div class="notice_section">

<div class="summary_section">

SUMMARY
The Microsoft Foundation Classes (MFC) provide a CFileException class. The CFileException class includes public data members that contain operating- system errors and C Run-time errors that may be generated by certain file operations.

<div class="moreinformation_section">

MORE INFORMATION
The CFile and CStdioFile classes may throw a CFileException when certain error conditions occur; however, these classes do not throw a CFileException when the end of file is reached. If an application using the CFile or CStdioFile class needs to check for the end-of-file condition when reading from a file, the return values from the Read and ReadString member functions should be checked.

CFile::Read returns the actual number of bytes read. If this number is less than the bytes requested, then the end of file has been reached.

CStdioFile::ReadString returns a NULL pointer when the end of file has been reached.

Additional query words: EOF TRY CATCH

Keywords: kbhowto kbfileio KB88769

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.