如何在构建时将文件的内容获取到我的 C++ 字符串中? [英] How can I get the contents of a file at build time into my C++ string?

查看:144
本文介绍了如何在构建时将文件的内容获取到我的 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.

这篇关于如何在构建时将文件的内容获取到我的 C++ 字符串中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆