Serializing a vector
-
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
-
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
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! ]
-
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
Note that in case of MFC,
CArray
andCArchive
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.
-
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
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