I need to get the byte stream of an object in C++. I could not find a way to do this without using serialization.
NodeEntry *one = new NodeEntry("mani", 34, 56.3);
ofstream rofs("result.ros", ios::binary);
rofs.write((char *)&one, sizeof(one));
rofs.close();
// now we read the file into object!!
ifstream ifsr("result.ros", ios::binary);
NodeEntry *oner;
ifsr.read((char *)&oner, sizeof(oner));
Is there any other workaround? I don't want to send this object through the network or store it on hard disk. I just want to get the byte stream of object one without actually creating the file.
In other word I need to create a byte stream of object one and store it somewhere (like in an ostream), then passing these bytes to another method and re-construct the object from these bytes.
I would appreciate if you give me a hint on this.