Classes allocating memory, reading/writing to file

Started by
9 comments, last by Destroyer 21 years, 8 months ago
quote:Original post by LousyPhreak

btw about the problems with private members:
write a _memberfunction_ to print out the contents of the class or make additional accessor functions like the one above. these functions dont even break the purpose of the private keyword as the value cant be changed (read only)


Never really thought about that. That seems like a nice solution as well . Thank you .

quote:Original post by DerekSaw


    class Dummy{  // same as previouspublic:  void Write(ostream &os);};void Dummy::Write(ostream &os){  os.write(&allocsize, sizeof allocsize);  for (int i = 0; i < allocsize; ++i)    os.write(buffer, allocsize);}Dummy* dumdum = new Dummy(64);int main(){  fstream iofile("Somefile", ios::out, ios::binary);dumdum->Write(iofile);  // and remember to delete your dumdum }  


I tested this out and it most definately seems to work. I wrote an reading equivilant and it works . Thank you very much. I never really thought about that as well .

Thanks to all! You've been a great help!

Destroyer




[edited by - Destroyer on August 27, 2002 11:06:49 AM]

This topic is closed to new replies.

Advertisement