Include files as string literals

Possible duplicate:
C / C ++, can you # include a file in a string literal?

Is it possible to get the entire contents of a text file as a string at compile time using C ++ 11 string literals?

Basically, I want to be able to embed GLSL shader source files without the need to modify them.

The following approach is suggested here :

const std::string shaderSource = R"glsl( #include "my_shader.glsl" )glsl"; 

This hacked, but that would be good for my application. However, this does not seem to work because the original string literals are evaluated before the file is included.

I assume that I could move the parts of the 'R"glsl(' and ')glsl"' to the beginning and end of each source shader file, and then just do this:

 const std::string shaderSource = #include "my_shader.glsl" ; 

But, as I said, I would prefer not to modify the original shader files, as this would complicate the loading of the same files at runtime and, therefore, would make them less portable.

+7
source share

All Articles