将文件的 hexdump 或 RAW 数据提取为文本
我想知道是否有办法将文件的 hexdump 或原始数据输出到 txt 文件。 例如 我有一个文件“data.jpg”(文件类型无关)如何将 HEXdump(14ed 5602 等)导出到文件“output.txt”? 另外我如何指定输出的格式,例如 Unicode 或 UTF? 在 C++ 中
I was wondering if there is a way to output the hexdump or raw data of a file to txt file.
for example
I have a file let's say "data.jpg" (the file type is irrelevant) how can I export the HEXdump (14ed 5602 etc) to a file "output.txt"?
also how I can I specify the format of the output for example, Unicode or UTF?
in C++
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用循环、fread 和 fprintf:通过 read,您可以获取字节的字节值,然后通过 fprintf,您可以使用
%x
将十六进制打印到文件中。如果你希望它更快,你可以加载整个机器字(int 或 long long)而不是单个字节,如果你希望它更快,你可以读取整个数组,然后 sprintf 整个数组,然后 fprintf 该数组到文件中。
You can use a loop, fread and fprintf: With read you get the byte-value of the bytes, then with fprintf you can use the
%x
to print hexadecimal to a file.If you want this to be fast you load whole machine-words (int or long long) instead of single bytes, if you want this to be even faster you fread a whole array, then sprintf a whole array, then fprintf that array to the file.
也许是这样的?
您只需将
buffer
替换为读取二进制文件的ifstream
,然后使用ofstream
而不是将输出写入文本文件>cout
。Maybe something like this?
You just have to replace
buffer
with anifstream
that reads the binary file, and write the output to a textfile using anofstream
instead ofcout
.这是相当古老的——如果你想要 Unicode,你必须自己添加它。
This is pretty old -- if you want Unicode, you'll have to add that yourself.