6

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.

senseiwa
  • 2,119
  • 1
  • 22
  • 37
  • maybe this will help http://stackoverflow.com/a/25021520/3512538 – CIsForCookies Apr 06 '17 at 13:26
  • No, it can't be done solely with the preprocessor. It would not be difficult to write a simple C or C++ program that reads the text file, and outputs a header containing the required string with suitable formatting. – Peter Apr 06 '17 at 13:31
  • Also may be of interest http://stackoverflow.com/questions/4864866/c-c-with-gcc-statically-add-resource-files-to-executable-library – Alex Che Apr 06 '17 at 13:32

1 Answers1

2

No, there isn't.

You will need external tools:

Community
  • 1
  • 1
Lightness Races in Orbit
  • 369,052
  • 73
  • 620
  • 1,021