Saving to a disk.

This is a discussion on Saving to a disk. within the C++ Programming forums, part of the General Programming Boards category; I was thinking.....using I/O is there any way to save the information that a specific class creates for example on ...

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Saving to a disk.

    I was thinking.....using I/O is there any way to save the information that a specific class creates for example on a disk and then retrieve that same information later......say if you were saying the records of a game......what key words should I look for if I want to find more info on it.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    Unregistered
    Guest
    yes

    FILE *, fscanf(),fprint(), etc if you want to use C style file handingl

    fstreams, ifstreams, ofstreams if you want ot use C++ style streams.

  3. #3
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Let's say I save a bunch of game information on example bert, josh or whatever, how would I get the right information for each person?
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    Using the above information and the fread, fwrite functions, you can save whole structures if they have a fixed length. There is no nice way to index a file. Simply read all records and check for your ID.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #5
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Using the above information and the fread, fwrite functions, you can save whole structures if they have a fixed length. There is no nice way to index a file. Simply read all records and check for your ID.

    what do you mean check for my id....I have an example on my book on how to save and read from a file. I think it's something like file.write((char*) & Bear, sizeof Bear); this would write the characters of the class bears on to the file or whatnot. But I mean what do you mean by check for my ID?

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    fread() and fwrite() are the C versions of the read() and write() methods for ifstreams and ofstreams respectively in C++. They will read/write all data members of an object to file at one time. If one of the data members is an id of some sort then you can read the values in file one object at a time, see if it has the id you want, if so do something, if not continue to next objects data. You could read all data in file to a container and then search each object in the container (array, list, vector, map, whatever) for the desired id/value.

    If the id correlates somehow to the offset of the objects data in file, then you could try using fseek() or associated file functions to go directly to that objects data in file and read it without "having" to search. In fact if you know the offset of the data member within the object you can probably go directly to the data value. But that is not something I have tried.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Saving binary tree data to disk
    By balazsbotond in forum C++ Programming
    Replies: 9
    Last Post: 12-09-2007, 09:46 AM
  2. Saving Map Array To Disk
    By Tommaso in forum Game Programming
    Replies: 4
    Last Post: 07-18-2003, 01:03 AM
  3. Formatting Output
    By Aakash Datt in forum C++ Programming
    Replies: 2
    Last Post: 05-16-2003, 09:20 PM
  4. Towers of Hanoi, special output.
    By spoon_ in forum C Programming
    Replies: 3
    Last Post: 03-15-2003, 06:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21