Text files with MFC

Text files with MFC

I have been reading Visual C++ 5 in 21 Days while trying to learn how to use the Visual C++ user interface, and I have been trying to find an example of how to read and save a text file using the MDI interface. Am I supposed to use the Serialize function or the CArchive class? I have been looking for an example all over the place, with no luck. (I have some prior C experience, but this new interface is taking some getting used to.)

In general, you would override the Serialize function to read and write your applications data. You could simply read the file into a CString object. However, this can give you unexpected characters in the file if you want to be able to read it using other programs such as NotePad.

If you need more control, you’ll probably need to bypass the standard CArchive method. I did this once and simply put custom code in OnOpenDocument and the other document routines associated with opening files.

For a complete example of one way to do this, check out the SuperPad demo in the Microsoft knowledgebase and Microsoft Developer Network CD.

See also  5 Ways to Improve Customer Experience

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist