Home > Back-end >  The question of structure written to the binary file
The question of structure written to the binary file

Time:12-05

Struct Test2
{
Int index;
}
Struct Test1
{
int id;
Vector};
Original intention is to want to put the Test1 this structure written to the binary file
Read write without error, but when looking at the data is wrong in the stack vecTest2
Is it time can't use the vector storage structure?
But I must keep a dynamic array, how can I solve???????

CodePudding user response:

Low-level file can be not only 01 binary string structure, how to write read need you to confirm the format, such as the length of the vector can be written in, and then read how many test1 according to determine the length of the read read

CodePudding user response:

reference 1/f, the truth is right or wrong response:
low-level file can be not only 01 binary string structure, how to write read need you to confirm the format, such as the length of the vector can be written in, and then read according to the length of the read read how many test1


Hello reading file size of the vector can be removed, is inside put int variables into random value



CodePudding user response:

reference 1/f, the truth is right or wrong response:
low-level file can be not only 01 binary string structure, how to write read need you to confirm the format, such as the length of the vector can be written in, and then read according to the length of the read read how many test1

You look at me, speaking, reading and writing the code
//write
TestData data;
Int nLong=vector. The size () * sizeof (int);
File. Write ((void *) & amp; The data, nLong);

//read
TestData data;
File. Read ((void *) & amp; Data to the file. The GetLength ());
Int size=(int) data. The TestList. The size ();
for (int i=0; I & lt; The size; I++)
{
Int val=data. TestList [I];//this is the right value read
}

CodePudding user response:

Vector is an object, not a memory, not directly to a file,
Baidu search "vector serialization deserialization." "
  • Related