S
S
sanek20052020-12-21 23:53:26
C++ / C#
sanek2005, 2020-12-21 23:53:26

Will this be serialization?

An object of a certain class is converted to a pointer to char into bits, and written through the stream to a file. Isn't this the notorious serialization?
If so, here's an example code:

ofstream out("lol.bin", ios::binary);

  Lol lol;

  lol.a = 129039;

  lol.b = 2012093319;

  out.write((char*)&lol, sizeof(Lol));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2020-12-21
@gbg

This will only work if all fields of the class are stored inside it, roughly speaking, if the class does not store any pointers or their surrogates (iterators).
If the field of your class is a pointer (or a surrogate), you will have to recursively serialize it already, which will result in a huge increase in complexity.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question