   Woohoo! Saved object to disk :)
  YESSS! Finally, I learned how to save objects to disk! This is great because it saves everything as one, so I don''t have to pass a billion variables to get saved. It works great with this source I wrote. I want to give special thanks to this site:http://www.gamedev.net/reference/articles/article1127.aspI thought I''d post this for the joy // Project: Object Saver // Author: Phillip Vaira// Description: Saving Object to Disk Using a Class// Include    ----------------------------------#include <iostream>#include <fstream.h>// Classes    ----------------------------------class Common{public:unsigned short getAge() const { return itsAge; }void setAge(unsigned short a_age) { itsAge = a_age; }private:unsigned short itsAge;};// Prototypes ----------------------------------// Main  ----------------------------------unsigned short main(void){using std::cout;using std::cin;using std::endl;Common Player;Player.setAge(22);// Writes Object to Diskofstream fout("a:test.dat", ios::binary);if (fout.is_open()){fout.write((char *) (&Player), sizeof(Player));fout.close();cout << "Saving is Complete!" << endl;}else{cout << "Error." << endl;}// Retrieves Object from Diskifstream fin("a:test.dat", ios::binary);if (fin.is_open()){fin.read((char *) (&Player), sizeof(Player));fin.close();cout << "Saving is Complete!" << endl;}else{cout << "Error." << endl;}// After opening object from disk...cout << Player.getAge() << endl;return 0;}    http://phil.webula.netAIM: wuZZup189 
  Your code is flawed.If you started to have virtual functions and hence vtables in your code or if you had any pointers or allocated data your code would crash and burn. Sorry to bust your bubble. ;  Congratulations.Two things I need to point out, though a) You should #include <fstream>, not #include <fstream.h>b) This code will only work so long as your class does not have a non-trivial constructor, does not have any virtual function, does not contain pointers, does not contain pointers to members, nor any object violating these restrictions. In C++ terms, it will only work for "POD-types". Saving each member variable one by one alleviates some of those restrictions.But, it''s already a good step in the right direction.  “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”    — Brian W. Kernighan (C programming language co-inventor);  Well, it's a start  It works fine for its purpose. Any urls you recremend after this url I posted above?   ps. By the way, only fstream.h works, so I guess I don't have the latest files aka fstream. I'm using Visual Studio 6.0.http://phil.webula.netAIM: wuZZup189 [edited by - philvaira on February 15, 2004 4:59:30 AM];quote:Original post by philvaira  ps. By the way, only fstream.h works, so I guess I don''t have the latest files aka fstream. I''m using Visual Studio 6.0.You need to change things like ofstream to std::ofstream, ios::binary to std::ios::binary etc.I need to emphasize that, because <iostream> and <fstream.h> are fatally incompatible.As for VC6, remember that you have service packs to apply: go to Microsoft''s website, download Visual Studio 6 service pack 5, as well as the processor pack.   “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”    — Brian W. Kernighan (C programming language co-inventor);  Yay, just downloaded the processor pack. I had no idea about this one. fstream now works too. Thanks  What''s the difference between fstream and fstream.h?   http://phil.webula.netAIM: wuZZup189 ;  fstream.h uses the global namespace, and it's depreciated. Don't use it.   [edited by - smart_idiot on February 15, 2004 5:24:40 PM]