Reads text data into a buffer, up to a limit of nMax–1 characters, from the file associated with the CStdioFile object.

virtual LPTSTR ReadString(
   LPTSTR lpsz,
   UINT nMax 
virtual BOOL ReadString(
   CString& rString


Specifies a pointer to a user-supplied buffer that will receive a null-terminated text string.


Specifies the maximum number of characters to read, not counting the terminating null character.


A reference to a CString object that will contain the string when the function returns.

A pointer to the buffer containing the text data. NULL if end-of-file was reached without reading any data; or if boolean, FALSE if end-of-file was reached without reading any data.

Reading is stopped by the first newline character. If, in that case, fewer than nMax–1 characters have been read, a newline character is stored in the buffer. A null character ('\0') is appended in either case.

CFile::Read is also available for text-mode input, but it does not terminate on a carriage return–linefeed pair.


The CString version of this function removes the '\n' if present; the LPTSTR version does not.

CStdioFile f(stdin);
TCHAR buf[100];

f.ReadString(buf, 99);

Header: afx.h

Community Additions