8

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.

5
  • maybe this will help stackoverflow.com/a/25021520/3512538 Commented Apr 6, 2017 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. Commented Apr 6, 2017 at 13:31
  • Also may be of interest stackoverflow.com/questions/4864866/… Commented Apr 6, 2017 at 13:32
  • static const std::string vertex_shader_text { #include "glmain.vert" }; Commented Jun 30, 2023 at 0:16
  • R"( #version 110 )" Commented Jun 30, 2023 at 0:17

1 Answer 1

2

No, there isn't.

You will need external tools:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.