【发布时间】:2017-01-06 21:34:30
【问题描述】:
我正在尝试使用 cmake 连接文件并在输出文件的末尾附加一个空字符(\0)。有谁知道如何在最后附加 null ?
concat 的代码是:
function(cat in_file1 in_file2 out_file)
file(READ ${in_file1} CONTENTS)
file(WRITE ${out_file} "${CONTENTS}")
file(READ ${in_file2} CONTENTS)
file(APPEND ${out_file} "${CONTENTS}")
endfunction()
要在末尾附加'\0',我尝试了以下方法:
file(APPEND ${out_file} NULL)
file(APPEND ${out_file} "\\0")
file(APPEND ${out_file} "\0" HEX)
但是这 3 个都不起作用。有人可以帮忙吗?
【问题讨论】:
-
Do you want to have the final file as with the text as it is seen in the input files or in HEX (e.g. the final file: 6369616f2c20736f6e6f0a73692c73690a7365636f6e646f2c206a6a6a6a0a6563636f6c6f20696c207365636f6e646f0a00)?如果您希望它作为文本,为什么要在末尾附加空字符?如果您想使用 HEX,那就另当别论了。
-
你试过
file(APPEND ${out_file} "\0")吗? -
@wasthishelpful:是的。它也不起作用。
-
@fedepad :我希望它作为一个二进制文件,包含所有文本和最后一个字符为空。流程是有一个 C++ 程序将这个文件作为一个字符串读取,并且它应该是空终止的。
标签: string file null cmake concatenation