Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <conio.h>
  3. #include <fstream.h>
  4.  
  5. class xyz
  6. {
  7. public:
  8. int x;
  9. };
  10.  
  11. void main()
  12. {
  13.  
  14. xyz a;
  15. a.x=45; //replace by 45 or 78 it works. Replace by 13, 26 it
  16. shows garbage values.
  17.  
  18. ofstream of;
  19. of.open("file.dat", ios::out||ios::binary);
  20. of.write((char*)&a, sizeof(a));
  21. of.close();
  22.  
  23. xyz b;
  24.  
  25. ifstream sf;
  26. sf.open("file.dat", ios::in||ios::binary);
  27. sf.read((char*)&b, sizeof(b));
  28. sf.close();
  29.  
  30. cout<<b.x;
  31. getch();
  32.  
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement