0

Is there a way to embed .txt files (their text) into a binary C++ program executable?

(EDIT: answered by the top comment)

What I mean by that, is, I want compile some .txt files into a single executable (.exe), so I don't need to depend on said files on the front end. Therefore, I only need to distribute a single .exe file and put it in any directory without the hassle of having to move a whole folder and making sure the executable is either ran from the command line or has to be in the root of a folder.

I search the web but couldn't find anything reasonable, that wouldn't take a lot of code and time.

Hope I made my question clear, thank you in advance for answers and opinions!

  • 2
    Yes, it's called _resources_ and a very common way of embedding data in binaries. – PMF Oct 18 '22 at 16:24
  • 3
    Since you mention `.exe` I assume you're on Windows? Then you could create a *resource file* to embed arbitrary text as resource that are linked into your executable program. This is very standard for Windows applications, but generally not used for larger files, or files that needs to be updated independently of the executable file (which is generally a good idea). – Some programmer dude Oct 18 '22 at 16:24
  • 4
    There are *installer* tools that help you package an executable with other files or resources. Search the internet for "C++ installer". – Thomas Matthews Oct 18 '22 at 16:29
  • 1
    Assuming you are on MS Windows and using `winapi` Related: [https://stackoverflow.com/questions/2933295/embed-text-file-in-a-resource-in-a-native-windows-application](https://stackoverflow.com/questions/2933295/embed-text-file-in-a-resource-in-a-native-windows-application) – drescherjm Oct 18 '22 at 16:31
  • 1
    ***Is there a way to build in some .txt files into a single C++ .exe?*** There are several ways. Some will use an OS api. Others could use a framework like Qt or an installer. – drescherjm Oct 18 '22 at 16:32
  • Sometimes I use [base64](https://en.wikipedia.org/wiki/Base64) to embed not too huge data directly in source files. – MatG Oct 18 '22 at 17:03

0 Answers0