我有以下问题。我想包含一个多行文本文件作为 #define
,即我需要的是一个存储文本文件值的常量。示例:
File 'f.txt': This\nis\n\nsome\ntext
并且我想以
的样式初始化一个常量(在编译时)#define txtfile "This\\nis\\na\\ntextfile"
其中字符串“This\nis\na\ntextfile”是通过连接文件 f.txt 中的行获得的。有什么方法可以使用预处理器命令/宏来实现吗?
最佳答案
看看"#include" a text file in a C program as a char[]寻找可能满足您需求的替代方案。
关于c++ - 使用预编译器的字符串连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/453107/