Thread: File Input/output

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    102

    File Input/output

    Hey Everyone, can anoyone explain how to create custom files and load and save any data you need for your programs, I can save to a text based file, but can't read from it. If you would recommend a site with some good tutorials. Or just give comments or source sample. I'd greatly appreciate it.
    My Favorite Programming Line:
    Code:
    #define true ((rand() % 2) ? true : false)

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    For basic file I/O in C++: http://www.cprogramming.com/tutorial/lesson10.html

    What exactly are you looking for? Something a little more in depth with saving a giant amount of data or something?

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    102
    Yes I'm looking for something to save large amounts of data, probably to numerous files. Im thinking of using a vector of strings to hold the filepaths and load large data into each file.
    I was hoping for something using the fread function. It seems to be more commonly used in my current book.
    My Favorite Programming Line:
    Code:
    #define true ((rand() % 2) ? true : false)

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    The problem with saving binary data is that when you use fwrite(), you tend to dump the data into a non-portable version. Check the issues of Endianness and also consider the sizes of certain variable types on different systems. Unless you want the file dumped to only be guarenteed to be read by the computer that wrote it, then you should look at a more portable solution.

    Saving strings, however, should generally be safe because they are stored in byte order, which has no bearing with endianess. Consider what it is you want saved and what you really want to do with the file in question. After that, come up with a file format that fits the requirements. Write a writetofile() and a readfromfile() pair of functions, and then you should be set.

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    102
    Sounds good, I'll try to make do with your previous mentioned way. Maybe I can try to compress my files a bit, hopefully it will work out well. Thanks again McGyver.
    My Favorite Programming Line:
    Code:
    #define true ((rand() % 2) ? true : false)

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. File being filled with NULLs
    By Tigers! in forum Windows Programming
    Replies: 2
    Last Post: 06-30-2009, 05:28 PM
  3. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM