I just noticed that the answer I gave for this question does not actually work:
Regardless of whether CMake is used or not, the following should work with the current standard:
std::string resource = R"( #include "text.txt" )";
I thought the pre-processor would recognize the #include "text.txt" in the first place and expand the text.
But this is obviously not the case, the result for
std::cout << resource << std::endl;
there is
#include "text.txt"
I tried using some macro so that the #include statement was expanded internally, but it doesnβt work either:
#include <string> #include <iostream> #define RESOURCE_DEFINIION(resource_var,resource_name) \ const std::string resource_var = R"xxx( \ #include resource_name \ )xxx"; RESOURCE_DEFINIION(resource,"text.txt") int main() { std::cout << resource << std::endl; return 0; }
Output signal
\ #include resource_name \
Here is a demo to play with
Are there any deceptive possibilities for attracting the text.txt resource to a literal with the source string C ++ - 11 using the preliminary processor or any other regular function of the C ++ language?
Denial of responsibility:
I know well what is wrong with the examples above and why they fail in this way. The problem is that the preprocessor ignores the material in pairs. "
So, is there a way to avoid this so that it can be seen in front of the processor?
c ++ c-preprocessor c ++ 11 string-literals
ΟάνΟΞ± αΏ₯Ξ΅αΏ
source share