Unknown File Opener?

Okay, so I think I have just passed the intermediate line in my skill of c++ and my question is how do I make a program that opens unknown files extensions. for example like .plr. Because I see a bunch of files for game modifications like that, that was a good reason I started c++ too.
The file extension actually doesn't mean anything about the contents of the file. You can save a file you've created with any extension and the contents will be identical. As an example, you could save a text file as "text.exe". Trying to run it would of course fail as the contents aren't what are expected of an executable, but you could open in a text editor with no issues.

To read a file, you need to know how its content is laid out otherwise it may as well just be a bunch of gibberish; the extensions are just used to help the user/OS see what the type of the file is meant to me, but as I said it is not a guarantee of any kind.
So you do it just as you were to import a .txt files to your program?
Basically, yes (just remember the difference between text and binary mode). The filestream library in C++ reads any kind of file, as fundamentally all file contents are just a bunch of bytes in a row. What you do with those bytes (how you interpret them) is up to you.

For example, I could have a file listing names I use for generating monster names or something for a game. The file could be a bunch of names separated by newlines, or maybe just bunch of null-terminated strings in a row instead. Either way, you have to know which way they are stored to be able to get a program to read them properly.

So to repeat, you can read any kind of file into your program. The only problem with reading a file of unknown type is that you don't know how the contents are to be read.
Thanks, I get it know.
Topic archived. No new replies allowed.