我想要使用可执行文件生成3个C ++文件,我的意思是如果我点击可执行文件,我的3个文件应该出现在它旁边。
所以我考虑使用ofstream
,然后像这样创建我的三个文件。但问题是,我的3个文件包含很多行并且转义为"
而'
会占用大量时间...
如何在没有逃避字符串文字的麻烦的情况下将C ++源代码嵌入到我的可执行文件中?
答案 0 :(得分:4)
If you're on Linux or similar, you can use objcopy
to do this easily during your build process:
objcopy --input binary --output elf64-x86-64 myfile.cpp myfiletxt.o
What this does is to create an object file called myfiletxt.o which you can then link into your executable. This object file will contain a symbol which is the entire content of myfile.cpp
. You can then print it out etc.