Resources

Disclaimer: Sorry if this doesn't really go here, I don't know where else to ask this.

Basically I need a multiplatform way of embedding data into c++ executables/libraries. Like Java can do. I want to be able to store images, text files, etc., without needing to carry around all the files.

Every answer I find says to create some class with the data and a size variable, etc. But I don't want to do this because how could this be practical if there's new data and data's changing...

Feel free to ask questions I'm not too good at explaining my problem. Thanks.
There are a number of ways to accomplish this; I don't know what Java does.

For binary data, my personal preference is to have a tool (xxd, usually) generate the source-code definition of an array containing the binary data. The definition can then be included directly into the program's source code.

See also the proposed std::embed, which describes a magic library component:
https://wg21.link/p1040r3
In particular, the section on current practice may be relevant to you.

Edit: link to an up-to-date paper
Last edited on
if the data changes, you should write it to a disk file. you can 'wad' all the stuff into a single file with some sort of 'table of contents' entry at the front end. Trying to modify the executable file with updated data can be done but its going to set off virus scanner alarms (potentially) and is probably a questionable practice. I mean, you can just open your executable file and append junk to the back end of it, it won't break anything on any platform I know of... And you need a way to know where your data starts...
Last edited on
I will try the idea with the generator. To clarify I don't mean edit the data in the program, I'm mean edit while making. Thanks.

But I don't want to do this because how could this be practical if there's new data and data's changing...


oh, if its static data its very easy to do. Or if its fixed by adding / changing and recompiling, that is also pretty easy.

Its changing it that is weird, so if you are not doing that, you have a winner.

If you have enough bytes of data, you can even compress it and embed the compressed data in the program and decompress it into memory when you need it.
Last edited on
Topic archived. No new replies allowed.