Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <fstream>
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. bool save(const DB_DB& db);
  7. bool load(const DB_DB& db);
  8.  
  9. string filename("database.dat");
  10.  
  11. int main(){
  12.     DB_DB database;
  13.    
  14.     //use save(database) or load(database)
  15.    
  16.     save(database);
  17.    
  18.     return 0;
  19. }
  20.  
  21.  
  22.  
  23. bool save(const DB_DB& db){
  24.        
  25.     ofstream outfile(filename.c_str(), ios::out|ios::binary);
  26.     if(!outfile){
  27.         return false;
  28.     }
  29.     if(!outfile.write((char*)&db, sizeof(DB_DB))){
  30.         return false;
  31.     }
  32.     outfile.close();
  33.     return true;
  34. }
  35.  
  36. bool load(const DB_DB& db){
  37.     ifstream infile(filename.c_str(), ios::in|ios::binary);
  38.     if(!infile){
  39.         return false;
  40.     }
  41.     if(!infile.read((char*)&db, sizeof(DB_DB))){
  42.         return false;
  43.     }
  44.     infile.close();
  45.     return true;
  46.    
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement