如何在 C++ 中处理来自 Perl/PHP 的打包数据?
我在用 C++ 实现 PHP 程序时遇到问题。它是关于 PHP/Perl 函数 unpack 的。我不知道如何在 C++ 中执行以下操作(读取文件没有问题......但我如何解压(“C *”)读取的内容)。
<?php
$file = fopen("bitmaskt.dat", "rb");
//create the data stream
$matrix_x = unpack("C*", fread($file, 286));
$matrix_y = unpack("C*", fread($file, 286));
$mask_data = unpack("C*", fread($file, 286));
$reed_ecc_codewords = ord(fread($file, 1));
$reed_blockorder = unpack("C*", fread($file, 128));
fclose($file);
?>
目前,我对自己解决这个问题感到非常绝望 - 我已经搜索了好几天,我发现的只是问题......有没有免费的 unpack() C++ 实现? :-(
I got a problem implementing a PHP programm in C++. It is about the PHP/Perl function unpack. I don't know how to do the follwing in C++ (no problem in reading a file... but how do i unpack("C*") the read contents).
<?php
$file = fopen("bitmaskt.dat", "rb");
//create the data stream
$matrix_x = unpack("C*", fread($file, 286));
$matrix_y = unpack("C*", fread($file, 286));
$mask_data = unpack("C*", fread($file, 286));
$reed_ecc_codewords = ord(fread($file, 1));
$reed_blockorder = unpack("C*", fread($file, 128));
fclose($file);
?>
Currently, I'm very hopeless solving this problem on my own - I'm searching for days, all I found are questions... Is there any free unpack() c++ implementation out there? :-(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Perl 的
pack
文档涵盖了使用的模板>打包
和解包
。假设您生成了
bitmaskt.dat
您可以使用以下命令读取它
例如:
输出:
Perl's documentation for
pack
covers the templates used forpack
andunpack
.Say you generated
bitmaskt.dat
withYou might read it with
For example:
Output:
我不知道 C++ 的 unpack 的任何一般实现,但这似乎不是您需要的东西。
如果matrix_x在某处定义为
unsigned char matrix_x[286]
并且您有一个打开的输入流inFile
那么你需要做的是
inFile.get(matrix_x, 286)
。这会从输入中读取 286 个字节,并将它们放入matrix_x
指向的数组中。I don't know about any general implementation of unpack for C++, but that doesn't seem to be the thing you need anyway.
if matrix_x is defined somewhere as
unsigned char matrix_x[286]
and you have an opened input streaminFile
then what you need to do is
inFile.get(matrix_x, 286)
. This reads 286 bytes from the input and places them in the array pointed to bymatrix_x
.