Thread: saving to a file with custom type (.lee or something)

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    saving to a file with custom type (.lee or something)

    ok, so i create this file in the same directory as my exe for my game. how would i make a file, like if i wanted a file like "Player.dml" so people couldn't edit it? then i do:

    ofstream save_file("Player.dml");

    save_file<<player.health;
    save_file<<"\n";
    save_file<<player.name;
    save_file.close();

    //later when i open
    char garbage[10];
    ifstream open_file("Player.dml");

    open_file>>player.health;
    open_file>>garbage;
    open_file>>player.name;
    open_file.close();
    //now i have all these variable values available?

    does it work like that? please answer both questions

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    For the most part the program doesn't make a distinction about the extension for the file, I could save all of my files as .pre and the program would have no trouble reading it. In fact, I've done just that quite a few times. What the program sees is whether the file is opened as textual or binary, not what type of file it is.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM