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

How can I get the contents of a file at build time into my C++ string?(如何在构建时将文件的内容获取到我的 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.

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

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

下一篇: C++ 库包含

基础教程推荐