CStdioFile::ReadString

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
);

Parameters

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

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

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

Return Value

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.

Remarks

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.

Note

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

Example

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

f.ReadString(buf, 99);

Requirements

Header: afx.h

See Also

Reference

CStdioFile Class

Hierarchy Chart

CStdioFile::WriteString

CFile::Read

Other Resources

CStdioFile Members