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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Reading CArchive in Serialize

Reading CArchive in Serialize

Scheduled Pinned Locked Moved C / C++ / MFC
question
8 Posts 2 Posters 1 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.
  • V Offline
    V Offline
    vasanth1004
    wrote on last edited by
    #1

    I'm trying to read whatever is stored in my document inside the Serialize method But, whenever I read into a string from the archive, it takes out that string from the archive. Thus, when I call the Baseclass serialize, the outputted Document is missing the string that was read. Is there a way to read such that the string is not taken out from the archive? I tried reading the string after I called the base class serialize, but I get only an empty string. Thanks, (code is below). void CRichedDoc::Serialize(CArchive& ar) { CString buf; ar.ReadString(buf); CRichEditDoc::m_bRTF = FALSE; CRichEditDoc::Serialize(ar); }

    D 1 Reply Last reply
    0
    • V vasanth1004

      I'm trying to read whatever is stored in my document inside the Serialize method But, whenever I read into a string from the archive, it takes out that string from the archive. Thus, when I call the Baseclass serialize, the outputted Document is missing the string that was read. Is there a way to read such that the string is not taken out from the archive? I tried reading the string after I called the base class serialize, but I get only an empty string. Thanks, (code is below). void CRichedDoc::Serialize(CArchive& ar) { CString buf; ar.ReadString(buf); CRichEditDoc::m_bRTF = FALSE; CRichEditDoc::Serialize(ar); }

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      vasanth1004 wrote: void CRichedDoc::Serialize(CArchive& ar) { CString buf; ar.ReadString(buf); CRichEditDoc::m_bRTF = FALSE; CRichEditDoc::Serialize(ar); } Shouldn't this be:

      void CRichedDoc::Serialize(CArchive& ar)
      {
      if (ar.IsStoring())
      ar << m_buf;
      else
      ar >> m_buf;
      }

      I've not ever used CRichEditDoc or m_bRTF so I may be way off.


      "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

      V 1 Reply Last reply
      0
      • D David Crow

        vasanth1004 wrote: void CRichedDoc::Serialize(CArchive& ar) { CString buf; ar.ReadString(buf); CRichEditDoc::m_bRTF = FALSE; CRichEditDoc::Serialize(ar); } Shouldn't this be:

        void CRichedDoc::Serialize(CArchive& ar)
        {
        if (ar.IsStoring())
        ar << m_buf;
        else
        ar >> m_buf;
        }

        I've not ever used CRichEditDoc or m_bRTF so I may be way off.


        "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

        V Offline
        V Offline
        vasanth1004
        wrote on last edited by
        #3

        What I had originally works, but it removes the string from the archive. I also tried creating a new archive by getting the filename from the passed archive, but it didn't make a difference. Thanks

        D 1 Reply Last reply
        0
        • V vasanth1004

          What I had originally works, but it removes the string from the archive. I also tried creating a new archive by getting the filename from the passed archive, but it didn't make a difference. Thanks

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          vasanth1004 wrote: What I had originally works... So what did you do that made it stop working?


          "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

          V 1 Reply Last reply
          0
          • D David Crow

            vasanth1004 wrote: What I had originally works... So what did you do that made it stop working?


            "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

            V Offline
            V Offline
            vasanth1004
            wrote on last edited by
            #5

            DavidCrow wrote: So what did you do that made it stop working? Sorry, I was wrong. It didn't work the way I wanted to: it reads it but also removes the string from the Archive. Basically I just want to read the contents of the current document into a String without removing what I read from the Archive. How do I do that?

            D 1 Reply Last reply
            0
            • V vasanth1004

              DavidCrow wrote: So what did you do that made it stop working? Sorry, I was wrong. It didn't work the way I wanted to: it reads it but also removes the string from the Archive. Basically I just want to read the contents of the current document into a String without removing what I read from the Archive. How do I do that?

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Put them into two separate variables and than concatenate them.


              "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

              V 1 Reply Last reply
              0
              • D David Crow

                Put them into two separate variables and than concatenate them.


                "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                V Offline
                V Offline
                vasanth1004
                wrote on last edited by
                #7

                The Strings?

                D 1 Reply Last reply
                0
                • V vasanth1004

                  The Strings?

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  Yes.


                  "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                  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