Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include a file as a string [duplicate]

Is there a preprocessor trick that allows me to "include" a file as a string in a header?

Something like this:

a.txt

lorem ipsum dolorem
sit amet

and the "magic" include call similar to this:

header.h

MAGICINCLUDE(a.txt, atxt)

As a result, the preprocessor does tricks and the above line is equivalent to this:

const char* atxt = "lorem ipsum dolorem\n\
sit amet";

No external tool shall be used, just the preprocessor: I am trying to get rid of my python scripts that do this.

like image 797
senseiwa Avatar asked Apr 06 '17 13:04

senseiwa


1 Answers

No, there isn't.

You will need external tools:

  • "#include" a text file in a C program as a char[]
  • C/C++ with GCC: Statically add resource files to executable/library
like image 198
Lightness Races in Orbit Avatar answered Nov 02 '22 00:11

Lightness Races in Orbit