如何在构建时将文件的内容获取到我的 C++ 字符串中?

2022-01-25 00:00:00 string include c++

I have a file I am compiling in C++ in which I wish to have a string whose value is the contents of a file at the time of compilation.

In other words, I'd like to #include the file but have that be inside double quotes.

How can I do this in C++?

Now what if that file contains double quotes as part of its text, how do I get those escaped?

解决方案

To correctly create a header with the correct null termination in the string use sed:

xxd -i ${INPUT_FILE_NAME} | sed s/};/,0x00};/ > ${INPUT_FILE_PATH}.h

See http://gamesfromwithin.com/quick-tip-working-with-shaders-on-ios for details.

相关文章