You mix std::basic_ostream::write
and printf
, which are unrelated. write
is for unformatted output of character/byte data, whereas printf
is c style formatted output.
Furthermore, you cannot write a class to disk and read it back that way, because the binary layout of an object, especially the address of the virtual function table, may differ from one run of the program to another.
In this special case, you even write and read only the pointer to dynamic memory. When you read the pointer back, the memory it is supposed to point to, might not be allocated anymore.
Better write an appropriate input and output operator, which reads and writes the needed members only.