New file type?

Started by
1 comment, last by silverphyre673 18 years, 10 months ago
How would i set up a new file type? and read,write to it? i need a file type ".config" that i could store things like Font=10, ect. how would i make this and read write from it?
Advertisement
Learn about "text" mode file reading and writing for whatever language you are using.

By the way, that ".config" is only there to tell windows what to do with the file when you click on it, so you can change the name and extension to whatever you want as long as you read/write it correctly.

To make the file, use a basic text editor like notepad, vi, gedit, textpad, etc.
Yep. There are only two types of files you work with. Text files are files that store text, like in a notepad or Word document. These are simple to read from and write to, but can be inefficient for storing large classes, and require you to parse the text to make something like a .config file usable in your program. You have to convert integers to text, and a user is more likely to screw up a text format file, because they *think* they know what they are doing.

You should learn about these first. They are easy to use and can be used for most purposes, at least for beginners.

The other kind of file format is binary. These store bytes of information. You can write numbers and such things directly, and can avoid parsing issues. These are much more complicated to learn, in my experiance. However, they are quite useful. I have a practical example in the following link, which took me a while to figure out how to do, and never generated much response :( Hope it helps.

If you are going to read/write to files, <fstream> is your best friend in C++.

[EDIT] Oh, yes... one other thing. File extensions have no neccesary correlation to what format they are in - again, text and binary are the ONLY two formats. They simply help specify what is stored in them, and how they should be used. For example, you can correlate .txt with a notepad file, and in Windows, when you double-click one, it launches notepad.exe. This functionality is build into Windows, and doesn't mean anything - in fact, you can load .txt files into your program easily, and you can change your Windows so .txt opens with Firefox, or MS Paint. It won't work for the latter, but if anyone cares to try, let me know what happens! :)
my siteGenius is 1% inspiration and 99% perspiration

This topic is closed to new replies.

Advertisement