在编译代码中包含一个大的文本变量是个好主意吗? [英] Is it a good idea to include a large text variable in compiled code?
问题描述
我正在编写一个程序,为用户生成一个格式化的文件,但它不仅生成格式化的文件,它更多。
I am writing a program that produces a formatted file for the user, but it's not only producing the formatted file, it does more.
我要分发单个二进制到最终用户,当用户运行程序时,它将为用户生成具有适当数据的xml文件。
I want to distribute a single binary to the end user and when the user runs the program, it will generate the xml file for the user with appropriate data.
为了实现这一点,我想以将文件内容提供给在代码中编译的字符数组变量。当用户运行程序时,我将写出该char文件为用户生成一个xml文件。
In order to achieve this, I want to give the file contents to a char array variable that is compiled in code. When the user runs the program, I will write out the char file to generate an xml file for the user.
char* buffers = "a xml format file contents, \
this represent many block text \
from a file,...";
我有两个问题。
Q1 。你有什么其他的想法,如何将我的文件内容编译成二进制,即分发为一个二进制文件。
Q1. Do you have any other ideas for how to compile my file contents into binary, i.e, distribute as one binary file.
Q2。这是一个好主意,如上所述?
Q2. Is this even a good idea as I described above?
推荐答案
我建议使用另一个文件包含数据,进入二进制,除非你有你自己的理由。我不知道其他可移植的方式把字符串放入二进制文件,但你的解决方案似乎确定。
I'll recommend using another file to contain data other than putting data into the binary, unless you have your own reasons. I don't know other portable ways to put strings into binary file, but your solution seems OK.
但是,请注意使用 \
在行的末尾以形成多行的字符串,缩进应该被照顾,因为它们从下一行的乞讨连接:
However, note that using \
at the end of line to form strings of multiple lines, the indentation should be taken care of, because they are concatenated from the begging of the next line:
char* buffers = "a xml format file contents, \
this represent many block text \
from a file,...";
或者您可以使用其他表单:
Or you can use another form:
char *buffers =
"a xml format file contents,"
"this represent many block text"
"from a file,...";
这篇关于在编译代码中包含一个大的文本变量是个好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!