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. Serialization & Reading/Write Multiple Lines :: MFC

Serialization & Reading/Write Multiple Lines :: MFC

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorialdata-structuresjson
6 Posts 4 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.
  • V Offline
    V Offline
    valikac
    wrote on last edited by
    #1

    Hello. My intention is to read each line from a file and save it into a STL list of CString. So if there are 10 lines in the file, then the linked list of CString will be of size ten. Prosise demonstrates a very effective way to read and write from and to a file linewise using the CStdioFile class. However, in doc/view, MFC turns to Serialization. The problem, to me, with Serialization is I do not know what is going on in the background. I do not know what the framework does to the data in terms of CArchive. When writing to CArchive, I use this: for (iter = list.begin(); iter != list.end(); ++iter) ar << *iter; I am not sure how to read data from CArchive back into the linked list. First, I do not know whether data is stored similar to a file, i.e. if you write line1 and line2, then you can read back line1 and line2 in its original form. How should I go about read data from CArchive back into the linked list if I have no knowledge of how CArchive manages the orientation of the data? For example let say that the linked list of CString has this: ----- a b c d e ----- Okay. When it stores the data into CArchive, I assumpt it stores it like this: <- a <- b <- c <- d <-e However, if I have no prior knowledge of what was in the CArchive, how do I go about saving the data from CArchive back into the linked list? Thanks, Kuphryn Note: If nothing works, I think the technique Prosise shows is best since class CStdioFile features ReadString() and WriteString().

    A A RaviBeeR 3 Replies Last reply
    0
    • V valikac

      Hello. My intention is to read each line from a file and save it into a STL list of CString. So if there are 10 lines in the file, then the linked list of CString will be of size ten. Prosise demonstrates a very effective way to read and write from and to a file linewise using the CStdioFile class. However, in doc/view, MFC turns to Serialization. The problem, to me, with Serialization is I do not know what is going on in the background. I do not know what the framework does to the data in terms of CArchive. When writing to CArchive, I use this: for (iter = list.begin(); iter != list.end(); ++iter) ar << *iter; I am not sure how to read data from CArchive back into the linked list. First, I do not know whether data is stored similar to a file, i.e. if you write line1 and line2, then you can read back line1 and line2 in its original form. How should I go about read data from CArchive back into the linked list if I have no knowledge of how CArchive manages the orientation of the data? For example let say that the linked list of CString has this: ----- a b c d e ----- Okay. When it stores the data into CArchive, I assumpt it stores it like this: <- a <- b <- c <- d <-e However, if I have no prior knowledge of what was in the CArchive, how do I go about saving the data from CArchive back into the linked list? Thanks, Kuphryn Note: If nothing works, I think the technique Prosise shows is best since class CStdioFile features ReadString() and WriteString().

      A Offline
      A Offline
      Alexandru Savescu
      wrote on last edited by
      #2

      If you store data in a CArchive like ar << line1; ar << line2; then you can safely read it like ar >> line1; ar >> line2; So to read data from the Archive use: CString a; ar << a; mylist.push_back (a); If you are not sure what is is in the archive then there may be o problem... Actually this is a more general problem. How can you read from a file if you are not sure what it's in it? Best regards, Alexandru Savescu

      V 1 Reply Last reply
      0
      • A Alexandru Savescu

        If you store data in a CArchive like ar << line1; ar << line2; then you can safely read it like ar >> line1; ar >> line2; So to read data from the Archive use: CString a; ar << a; mylist.push_back (a); If you are not sure what is is in the archive then there may be o problem... Actually this is a more general problem. How can you read from a file if you are not sure what it's in it? Best regards, Alexandru Savescu

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

        Thanks! You cleared up some of my confusion. The datafile my program read/write has a certain data format. I read the data in line by line. I am intrigued about reading data from a *line by line* when you do not know its content too. Maybe someone can add to that. Thanks, Kuphryn

        1 Reply Last reply
        0
        • V valikac

          Hello. My intention is to read each line from a file and save it into a STL list of CString. So if there are 10 lines in the file, then the linked list of CString will be of size ten. Prosise demonstrates a very effective way to read and write from and to a file linewise using the CStdioFile class. However, in doc/view, MFC turns to Serialization. The problem, to me, with Serialization is I do not know what is going on in the background. I do not know what the framework does to the data in terms of CArchive. When writing to CArchive, I use this: for (iter = list.begin(); iter != list.end(); ++iter) ar << *iter; I am not sure how to read data from CArchive back into the linked list. First, I do not know whether data is stored similar to a file, i.e. if you write line1 and line2, then you can read back line1 and line2 in its original form. How should I go about read data from CArchive back into the linked list if I have no knowledge of how CArchive manages the orientation of the data? For example let say that the linked list of CString has this: ----- a b c d e ----- Okay. When it stores the data into CArchive, I assumpt it stores it like this: <- a <- b <- c <- d <-e However, if I have no prior knowledge of what was in the CArchive, how do I go about saving the data from CArchive back into the linked list? Thanks, Kuphryn Note: If nothing works, I think the technique Prosise shows is best since class CStdioFile features ReadString() and WriteString().

          A Offline
          A Offline
          AlexMarbus
          wrote on last edited by
          #4

          Wouldn't it be easier (if it's possible in your app) to use a CStringList or CStringArray and serialize that one, using CStringList::Serialize or CStringArray::Serialize? (Just a thought) -- Alex Marbus www.marbus.net But then again, I could be wrong.

          V 1 Reply Last reply
          0
          • V valikac

            Hello. My intention is to read each line from a file and save it into a STL list of CString. So if there are 10 lines in the file, then the linked list of CString will be of size ten. Prosise demonstrates a very effective way to read and write from and to a file linewise using the CStdioFile class. However, in doc/view, MFC turns to Serialization. The problem, to me, with Serialization is I do not know what is going on in the background. I do not know what the framework does to the data in terms of CArchive. When writing to CArchive, I use this: for (iter = list.begin(); iter != list.end(); ++iter) ar << *iter; I am not sure how to read data from CArchive back into the linked list. First, I do not know whether data is stored similar to a file, i.e. if you write line1 and line2, then you can read back line1 and line2 in its original form. How should I go about read data from CArchive back into the linked list if I have no knowledge of how CArchive manages the orientation of the data? For example let say that the linked list of CString has this: ----- a b c d e ----- Okay. When it stores the data into CArchive, I assumpt it stores it like this: <- a <- b <- c <- d <-e However, if I have no prior knowledge of what was in the CArchive, how do I go about saving the data from CArchive back into the linked list? Thanks, Kuphryn Note: If nothing works, I think the technique Prosise shows is best since class CStdioFile features ReadString() and WriteString().

            RaviBeeR Offline
            RaviBeeR Offline
            RaviBee
            wrote on last edited by
            #5

            This article may help. /ravi

            1 Reply Last reply
            0
            • A AlexMarbus

              Wouldn't it be easier (if it's possible in your app) to use a CStringList or CStringArray and serialize that one, using CStringList::Serialize or CStringArray::Serialize? (Just a thought) -- Alex Marbus www.marbus.net But then again, I could be wrong.

              V Offline
              V Offline
              valikac
              wrote on last edited by
              #6

              Very good point! I will considering the CStringList ASAP. I will post an update. Thanks, Kuphryn

              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