Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Opening/Editing a simple text file

Opening/Editing a simple text file

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialdatabase
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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:

    T 1 Reply Last reply
    0
    • L Lost User

      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:

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      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

      L 1 Reply Last reply
      0
      • T Tomasz Sowinski

        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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • L Lost User

          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.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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

          M 1 Reply Last reply
          0
          • L Lost User

            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

            M Offline
            M Offline
            Mark Terrano
            wrote on last edited by
            #5

            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)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups