-
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.
-
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?
-
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.
-
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.
-
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.