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

查看:75
本文介绍了如何在构建时获取文件的内容到我的C ++字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件,我在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.

我该如何在C ++中做这个?

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?

推荐答案

要在字符串中正确创建带有正确空终止的标头,请使用sed:

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

查看 http://gamesfromwithin.com/quick-tip-working-with-shaders-on-ios 了解详情。

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

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