home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 12888 < prev    next >
Encoding:
Text File  |  1992-08-25  |  1.0 KB  |  29 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!bunyip.cc.uq.oz.au!griffin!kurango!gucis!jetherid
  3. From: jetherid@gucis.cit.gu.edu.au (Jason Etheridge)
  4. Subject: File I/O using C++ (write/read objects...)
  5. Message-ID: <1992Aug26.023255.10785@gucis.cit.gu.edu.au>
  6. Organization: Griffith University, Brisbane, Australia.
  7. Date: Wed, 26 Aug 92 02:32:55 GMT
  8. Lines: 19
  9.  
  10. I am having real problems reading and writing objects to a file.  A text
  11. I have uses
  12.  
  13.     out.write((unsigned char*) &object, sizeof(OBJECT))
  14.  
  15. where out is an fstream that allows writing to the file it is open for,
  16. and object is an object of class OBJECT.
  17.  
  18. It writes the object, seemingly with no problems, but when I try and read
  19. it back in the resulting object has been garbled, it's attributes changed
  20. with the occasional garbage character.
  21.  
  22. Strangely enough, if I try this with an object with no functions, it
  23. works perfectly.
  24.  
  25. Can anyone suggest a good way of writing and reading objects to a file
  26. that really works?
  27.  
  28. (I am using the Borland C++ 3.0 compiler)
  29.