This tip comes from a couple of posts in
comp.os.ms-windows.programmer.tools.mfc...
Hi!
I'm an MFC newbie and I've been struggling with the file I/O
aspects of C++ / MFC.
I want to just read in (and write out) a text file, but
when I use ClassWizard, it seems to want to stick some
kind of versioning information in the I/O stream (like
its "typing" each kind of file).
Can anyone point to an example, or give me a clue on the
right way to implement the file i/o?
Thanks!
If you just want to read/write a file, then you can do it with CFile.
For example:
CFile myFile;
char szBuffer[40];
// put some data in c:\myfile.dat
myFile.Open("c:\\myfile.dat", CFile::modeCreate);
lstrcpy(szBuffer, "put this in the file");
myFile.Write(szBuffer, lstrlen(szBuffer));
myFile.Close();
// read from c:\myfile.dat
myFile.Open("c:\\myfile.dat", CFile::modeRead);
myFile.Read(szBuffer, sizeof(szBuffer));
myFile.Close();
Abu Wawda
wawda@scf.usc.edu
> Try CStdioFile. It allows you to use very simple functions like
> ReadString() and WriteString() to do file IO.
Fantastic! I have learned something new! God I love this.... I have
been using the fopen and fgets for so long, and now I can drop them.
Hmmmmm, maybe looking at the manuals would be a good thing......