I have a text file containing resources my application needs. The file contains arbitrary plain text, not C++ code with variable assignments. I don't want to ship the text file along with my application; I'd prefer to compile it into it. So I tried the following:
#include <iostream>
#include <string>
int main() {
std::string test = R"(
#include <textresource.txt>
)";
std::cerr << test << std::endl;
}
I expected the #include
in line 6 to be executed at preprocessing time, getting replaced with the contents of the resource file. After that, the compiler would see a raw string literal with the resource data.
However, the output is simply the text #include <textresource.txt>
with newlines around it. So apparently, the #include
is never executed. (I'm using Visual Studio 2015.)
Why doesn't the #include
work as expected? Is there some other syntax that will import a text file (not code) into a variable at compile time?