Is there a platform-independent method to embed file data into a c++ program? For instance, I am making a game, and the levels are stored in text format. But I don't want to distribute those text files with the game itself. What are my options?
3 Answers
This has been asked here before. Basically, you just name the data with an accessible symbol. I like this method best:
You can always write a small program or script to convert your text file into a header > > file and run it as part of your build process.

- 1
- 1

- 7,518
- 3
- 26
- 33
You can always put the text in the code. Say, for example, as an array of Strings or array of pointers to characters.
String txt[] = {
"My first line.\n",
"My second line.\n"
}
Of course there are better structures in the standard libraries, but in any case you put the text in a source file.
You could also consider putting the text into the package and encrypting it, if you're worried about people accessing it.

- 110,348
- 25
- 193
- 263
If the levels are really stored simply as text, you could just declare static char arrays in your source:
static const char level1[] = "abcdeabcdeabcde....";
You can compile and link this right into your application and reference it just like any other variable.

- 16,432
- 3
- 38
- 52