I have a source input file
long content to be included
And want to include it and handle as a string
const char* mydata =
#include "myfile.txt"
;
I need to make the content becomes raw string as
R"(long content to be included)"
Thanks for your suggestions. I find a solution for my problem with configure_file api.
#include <iostream>
#include <stdio.h>
#include <string>
const char *test_data = R"(
@FILE_CONTENT@
)";
int main() { printf("%s\n", test_data); }
file(READ resources/data.txt FILE_CONTENT)
configure_file(test.cpp.in test.cpp @ONLY)
R"(to the header file. Append the contents of the input file. Append"). I think CMake have functionality to do all of that built-in, you might want to read its documentation. Otherwise you can invoke external OS-specific commands to do it (for example on POSIX systems like Linux or macOS you can useechoandcat). If you use the external solution, I recommend you create a simple script which does it all, and invoke that from CMake. Now you try, and tell us how your attempt worked or not.configure_filewith the@ONLYoption to fill in the file from a template.