English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hello, I am wondering in most they have their own file types (such as .sav for a game save and .esm for a Elder Scrolls file) Just wondering how do they create, acess and delete them using C++? Can anyone give me an explaination, point me towards a tutorial or tell me a book i could get with this in it.

- Cheers, Daniel

2006-08-12 12:33:10 · 4 answers · asked by Peter 1 in Computers & Internet Programming & Design

4 answers

To read or write text files in C++, you usually use stream objects of the standard classes "ifstream" and "ofstream." Those classes also have open and close functions and the appropriate overloaded stream operators. There is nothing really special about the different types of file name extensions, although it helps to choose a unique one that means something in the context (like an abbreviation). To read or write binary data in C++ (for example, from data structures), there are other functions you can use called "read" and "write." They take character buffers as their arguments, but you can cast any buffer to a buffer of characters so that doesn't matter. This appears to be a good place for you to start learning about it: http://www.angelfire.com/country/aldev0/cpphowto/cpp_BinaryFileIO.html
This is another tutorial-like reference related to the subject:
http://www.developer.com/net/cplus/article.php/10919_2119781_1
Another handy reference (but not a tutorial) is http://www.cppreference.com/

There's nothing particularly special about writing to files per se. The main difference between writing to files and to the console is that you have to decide on a good format for your files if you intend to read them later on. Good luck!

2006-08-12 13:52:43 · answer #1 · answered by anonymous 7 · 0 0

If you've ever tried opening a data file (such as a saved game file) in notepad you've probably noticed that it just looks like a bunch of gibberish. That's because when you open a file in Notepad, it has certain assumptions that it makes about the file that aren't true.

Almost all text files are encoded with 7-bit data, since 7 bits can sufficiently hold all the letters, numbers, punctuation and control characters you need.

Data files are almost always encoded in 8-bit data. So when notepad starts reading it, it looks like gibberish.

Files in C++ are handled almost exactly like input/output from the keyboard and to the screen. Except instead of using the devices, it uses file streams.

To open a file steam, you se the fstream.open() function. The parameters that you pass that function determine whether you will be reading to it, writing to it, or both.

From there you read in data just like you would read in data from the keyboard. Except the data might be more optimized than text.

You coud fit 8 different flags into a single byte of data. A flag is just a specific bit that signifies something. For example, if the first bit of the byte is a '1' it might mean that you've beaten a certain area of the game.

2006-08-12 12:52:02 · answer #2 · answered by sovbob 3 · 0 0

These are input output operations that are available in every language.
I would rather advise you to move with C# than C++ if your developing for the windows environment.

2006-08-12 12:52:21 · answer #3 · answered by Alpha-Male 1 · 0 0

it is so uncomplicated as this: #comprise iostream #comprise fstream #comprise string utilising namespace std; int considerable(int argc, char *argv[]) {     string filename;     cout << "enter call of record to create: ";     getline(cin,filename);     ofstream outFile(filename.c_str());     if (outFile.is_open()) {         outFile << "hi, worldwide." << endl;         outFile.close();     } else {         cout << "blunders beginning " << filename << endl;     }     return(0); } pattern run: $ ./fileTst enter call of record to create: hi.txt $ cat hi.txt hi, worldwide.

2016-11-04 11:13:21 · answer #4 · answered by ? 4 · 0 0

fedest.com, questions and answers