Thread: need help

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    291

    need help

    Does anyone have a good tutorial on howto save an object to file and restore it ?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    To save one integer (in text):
    Code:
    void SaveData(int Data)
    {
       ofstream WriteFile;
    
       WriteFile.open("Save.dat", ios::out);
       if(!WriteFile.fail())
       {
          WriteFile << Data;
          WriteFile.close();
       }
    }
    
    int LoadData()
    {
       ifstream ReadFile;
       int Data = 0;
    
       ReadFile.open("Save.dat", ios::in);
       if(!ReadFile.fail())
       {
          ReadFile >> Data;
          ReadFile.close();
       }
       return Data;
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed