Opening/Editing a simple text file
-
I've got a project here that's supposed to open a custom-formatted text file (its just a record file delimited with the | (pipe) symbol) and I'm having the darnedest trouble trying to figure out how to open it, work with the CArchive, and assign values to the variables I already have. I know this is easy, but I don't know enough MFC/STL to do this. I generated a project with the MFC AppWiz (SDI, no database support), so I've got standard Wizard-generated code to work with. It'll be easiest if someone has example code for me, because I am totally at a loss.:confused:
-
I've got a project here that's supposed to open a custom-formatted text file (its just a record file delimited with the | (pipe) symbol) and I'm having the darnedest trouble trying to figure out how to open it, work with the CArchive, and assign values to the variables I already have. I know this is easy, but I don't know enough MFC/STL to do this. I generated a project with the MFC AppWiz (SDI, no database support), so I've got standard Wizard-generated code to work with. It'll be easiest if someone has example code for me, because I am totally at a loss.:confused:
Say goodbye to CArchive. If your program has a custom format, you need to override OnOpenDocument and OnSaveDocument in your CDocument-derived class. Use stdio's FILE, MFC's CFile, STL's iostream or Windows API to read/write file contents - CArchive will not help here. Tomasz Sowinski -- http://www.shooltz.com.pl
-
Say goodbye to CArchive. If your program has a custom format, you need to override OnOpenDocument and OnSaveDocument in your CDocument-derived class. Use stdio's FILE, MFC's CFile, STL's iostream or Windows API to read/write file contents - CArchive will not help here. Tomasz Sowinski -- http://www.shooltz.com.pl
I had a practice DOS version of this program running, using fstream, but unfortunately, the read/write operations are slow. In the Windows version I'm writing now, I'd like to have immediate response when moving back and forth between records. Will fstream be more responsive in Windows than it was in DOS, or can I expect the same delay when it reads/writes the disk? I'm assuming it'll be as slow, because fstream isn't buffered like CArchive/CFile. Right now I'm reading Leo Moll's Property Sheet View article. It looks like it can help me out. I think I'm missing a lot more information than just working with the file I/O.
-
I had a practice DOS version of this program running, using fstream, but unfortunately, the read/write operations are slow. In the Windows version I'm writing now, I'd like to have immediate response when moving back and forth between records. Will fstream be more responsive in Windows than it was in DOS, or can I expect the same delay when it reads/writes the disk? I'm assuming it'll be as slow, because fstream isn't buffered like CArchive/CFile. Right now I'm reading Leo Moll's Property Sheet View article. It looks like it can help me out. I think I'm missing a lot more information than just working with the file I/O.
Is fstream the usual way how people do file IO. In my case I wanted to save a string to a file. I didnt know whether htis should go into a CArchive object. in fact I havent got a clue when it comes to CArchive and serialisation. It seems a complicated subject.... Can I put strings/ints etc into archives and then pass them to serialize() thanks in advance
-
Is fstream the usual way how people do file IO. In my case I wanted to save a string to a file. I didnt know whether htis should go into a CArchive object. in fact I havent got a clue when it comes to CArchive and serialisation. It seems a complicated subject.... Can I put strings/ints etc into archives and then pass them to serialize() thanks in advance
If you're using MFC, just (typing from memory here, not pasting - so excuse any typos -the help for CFile::Write has examples I believe) ----- CFile savestring; savestring.Open("Myfile.txt", CFile::modeWrite); size = myString.getLength()+1; //use whatever you need. Not sure if buffer rqd. savestirng.Write( myString.getBuffer(size), size); savestring.Close(); If you have a format for the line, you can just as easily write out your storage class in the 'Write'. CArchive seemed like more of a hassle than just writing things out myself - I messed with it for awhile but had problems with the arrangement of the various macros for Implement_Dynamic and whatnot. --Mark Terrano www.ensemblestudios.com (Creators of the Age of Empires series)