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. Serializing a vector

Serializing a vector

Scheduled Pinned Locked Moved C / C++ / MFC
graphicstutorialquestion
4 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.
  • A Offline
    A Offline
    AbhishekBK
    wrote on last edited by
    #1

    Hello people. I am trying to serilaize a class which has a vector. I put the vector into a class and tried my luck, but no avail. Could somebody show\tell\advice me about how to serilaize a vector and read it back, (when the size of the vecor is not known at compile time)? Thanks in advance.

    Abhishek

    T V A 3 Replies Last reply
    0
    • A AbhishekBK

      Hello people. I am trying to serilaize a class which has a vector. I put the vector into a class and tried my luck, but no avail. Could somebody show\tell\advice me about how to serilaize a vector and read it back, (when the size of the vecor is not known at compile time)? Thanks in advance.

      Abhishek

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      what you have to do is basically this : serialize first the number of elements in the vector then, loop on the vector and serialize each object. (the classes contained in the vector mest be serializable, of course). when you'll try to deserialize, read the number of elements that come next, and loop to deserialize the objects...


      TOXCCT >>> GEII power

      [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

      1 Reply Last reply
      0
      • A AbhishekBK

        Hello people. I am trying to serilaize a class which has a vector. I put the vector into a class and tried my luck, but no avail. Could somebody show\tell\advice me about how to serilaize a vector and read it back, (when the size of the vecor is not known at compile time)? Thanks in advance.

        Abhishek

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

        Note that in case of MFC, CArray and CArchive classes, the serialization and de-serialization of a vector can be done in this manner:

        CArray my_vector;
        CArchive ar(...);
        
        my_vector.Serialize(ar);
        

        I think you should specify which kind of vector are you using.

        1 Reply Last reply
        0
        • A AbhishekBK

          Hello people. I am trying to serilaize a class which has a vector. I put the vector into a class and tried my luck, but no avail. Could somebody show\tell\advice me about how to serilaize a vector and read it back, (when the size of the vecor is not known at compile time)? Thanks in advance.

          Abhishek

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

          Actually I am guilty of not having described my problem sufficiently. I am not using MFC in my program. I am trying to sterilize everything by using the ofstream::write((char*)&Object, sizeof(object)); That's because I am working on an AutoCAD plug-in that requires an extra bit of gymnastics to use MFC. Also, I did not want to eliminate suggestions by talking too much of my idea of the problem. But here it is: I am writing a project handling tool that handles "n" number of files as a project. Data from each file is kept in a structure\class (say FileStruct) in 2 2D arrays and a few strings. I wanted to replace these 2D arrays by vectors. Also the project itself is only a collection of "n" number of FileStructs. So wanted to make a vector out for that as well. So the final object waiting to be serialized would conceptually look like this: Object X { vector[FileStruct] { vector<2D_array_replaced>; } } But from the looks of it, I have to use MFC now. I tried boost, but I am just not being able build the serialization library with VC 7.0 (which is what I have to use for AutoCAD plug-in) What do you guys suggest? Abhishek

          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