如何在构建时将文件的内容获取到我的 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
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Clang Tool (libtooling): set header search path to standard libs headers. Foundation framework(Clang 工具 (libtooling):将标头搜索路径设置为标准库标头.基础框架)
C++ Library Include(C++ 库包含)
C++ previous definition error(C++以前的定义错误)
Writing or Copying Visual C++ console output to text file(将 Visual C++ 控制台输出写入或复制到文本文件)
C++ class, its base class and circular include includes(C++ 类,它的基类和循环包含包括)
How to see the actual order of include files after preprocessing?(预处理后如何查看包含文件的实际顺序?)