INFO: Write() Function (92803)



The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), when used with:
    • Microsoft Visual C++, 32-bit Editions 1.0
    • Microsoft Visual C++, 32-bit Editions 2.0
    • Microsoft Visual C++, 32-bit Editions 2.1
    • Microsoft Visual C++, 32-bit Editions 4.0
    • Microsoft Visual C++, 32-bit Editions 4.1
    • Microsoft Visual C++ for Windows, 16-bit edition 1.0
    • Microsoft Visual C++ for Windows, 16-bit edition 1.5
    • Microsoft Visual C++ for Windows, 16-bit edition 1.51
    • Microsoft Visual C++ for Windows, 16-bit edition 1.52

This article was previously published under Q92803

SUMMARY

In an application developed with the Microsoft Foundation Classes (MFC) that uses the CFile class, the Write() member function may appear not to correctly process the carriage return-linefeed (CR/LF) combination unless both the carriage return and linefeed are explicitly stated.

For example, the following code
   CFile file;
   // ...
   file.Write("Hello\n", 6);
   file.Write("Hello\n", 6);
				
produces the following output:
-------------------
Hello
     Hello
-------------------
However, the following code
   file.Write("Hello\n\r", 7);
   file.Write("Hello\n\r", 7);
				
produces the following output:
-------------------
Hello
Hello
-------------------
					

MORE INFORMATION

When an application uses the CStdioFile class derived from CFile, an application can open a file in either text mode or binary mode. Using a CStdioFile object is the preferred method to place a CR/LF combination into a file. However, if the application must use a CFile object, a CR/LF combination may be explicitly output as demonstrated above.

Modification Type:MajorLast Reviewed:12/11/2003
Keywords:kbFileIO kbinfo KB92803 kbAudDeveloper