Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #include <conio.h>
- #include <fstream.h>
- class xyz
- {
- public:
- int x;
- };
- void main()
- {
- xyz a;
- a.x=45; //replace by 45 or 78 it works. Replace by 13, 26 it
- shows garbage values.
- ofstream of;
- of.open("file.dat", ios::out||ios::binary);
- of.write((char*)&a, sizeof(a));
- of.close();
- xyz b;
- ifstream sf;
- sf.open("file.dat", ios::in||ios::binary);
- sf.read((char*)&b, sizeof(b));
- sf.close();
- cout<<b.x;
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement