Guest User

Untitled

a guest
Jun 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <fstream.h>
  3. #include <iomanip.h>
  4. #include "Person.h"
  5.  
  6. void main()
  7. {
  8. Person p;
  9. Person q;
  10.  
  11. fstream file; //stream for input AND output
  12. file.open("People.dat",ios::in|ios::out);
  13.  
  14. cout<<"Enetr details of 1 Person: \n";
  15. p.readData();
  16. file.write((char*)&p,sizeof(p));
  17.  
  18. file.seekg(0); //go to the start
  19. cout<<"\nReading from the file: \n";
  20. //here you can user while(file) if you dont know how big the file is
  21. //Invoked on a differnt object just to prove it works :D
  22. file.read((char*)&q,sizeof(q));
  23. q.writeData();
  24.  
  25. file.close();
  26. }
Add Comment
Please, Sign In to add comment