The information in this article applies to:
SYMPTOMSReading long strings (greater than 128 characters) from a CStdioFile with the ReadString method can result in truncated or incorrect data being returned in the string. CAUSEThe pointer math used in calculating buffer offsets was incorrect in the code for CStdioFile::ReadString(CString& rString) in FILETXT.CPP. RESOLUTIONThe solution was a rewriting of the MFC code for CStdioFile::ReadString(CString& rString). The following code is from the MFC 4.1 source:
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in the Microsoft Foundation Classes (MFC), included with: Microsoft Visual C++, 32-bit Edition, version 4.1. MORE INFORMATION
When you invoke ReadString, CStdioFile::ReadString(CString& rString) enters
an infinite loop that breaks when the string is completely read in or EOF
is reached. It reads your string in chunks of 128 bytes, but the pointer
that ReadString uses to position the next read into the string is being
shifted by 256 bytes. This results in bytes 129 through 256 being
undefined. Sample CodeThe following code demonstrates the problem. It assumes you have a CString that has a large buffer already allocated for it, such as 256 bytes. You want to read a line that contains 140 bytes:
You must supply a file (titled c:\test.txt in the example) that contains at
least two strings with more than 128 characters in each string for the
problem to be manifested.
Additional query words: 4.00
Keywords : kbFileIO kbMFC kbVC |
Last Reviewed: July 28, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |