Hi,
Ok I've tried doing the object serialization, but it doesn't quite work. Here's what I have:
Code:
#include <fstream>
#include <iostream>
using namespace std;
class My_Class
{
public: My_Class(){};
My_Class(int a, int b)
{
x = a;
y = b;
};
private:
int x;
int y;
};
int main()
{
My_Class my_class1(2, 5);
ofstream ofs("D:\\my_class.ros", ios::binary);
ofs.write((char *)&my_class1, sizeof(my_class1));
My_Class my_class2;
ifstream ifs("D:\\my_class.ros", ios::binary);
ifs.read((char *)&my_class2, sizeof(my_class2));
}
It compiles fine, and it writes ok to the .ros file. However, when I read this file into my_class2, it doesn't set the variables of my_class2 to be equal to those of my_class1, like I want it to. It doesn't set my_class2.x and my_class2.y to anything - they are left at -85983560 or something...
Any ideas on what I am doing wrong? I followed this example from a tutorial and I can't see any differences between my code and theirs...
Thanks!