Int 和 *Char 数组 - C++
我想使用 LZO 来压缩 int 或 byte 数组。所以我需要将 int 数组复制到 *char 然后我将压缩并保存到文件。然后我需要做反向操作。我将打开文件,用 *Char 读取它,并将其解压缩为 int 数组。
我不想查看 *char 来转换每个 int。有什么方法可以快速做到这一点吗?
char *entrada;
int *arrayInt2;
int arrayInt1[100];
int ctr;
for(ctr=0;ctr<=100; ctr++)
{
arrayInt1[ctr] = ctr;
}
entrada = reinterpret_cast<char *>(arrayInt1);
arrayInt2 = reinterpret_cast<int *>(entrada);
return 0;
我想要这样的东西。这是正确的吗? 谢谢
I want to use LZO to compress a array of int or byte. So I need to copy the int array to a *char then I will compress and save to file. And after i need do reverse operation. I will open the file read it with *Char and the decompress to array of int.
I don't want to do a look in the *char to convert each int. Is the any way to do this quickily?
char *entrada;
int *arrayInt2;
int arrayInt1[100];
int ctr;
for(ctr=0;ctr<=100; ctr++)
{
arrayInt1[ctr] = ctr;
}
entrada = reinterpret_cast<char *>(arrayInt1);
arrayInt2 = reinterpret_cast<int *>(entrada);
return 0;
I want something like this. Is this correct?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将整数数组直接视为(二进制)字符缓冲区并将其传递给压缩函数:
同样,当您解压缩到字符缓冲区时,您可以将其用作整数数组:
确保跟踪原始数据整数数组的长度并且您不会访问无效索引。
You can treat the integer array directly as a (binary) character buffer and pass it to your compression function:
And similarly when you decompress into a character buffer, you can use it as an integer array:
Make sure that you keep track of the original length of the integer array and that you don't access invalid indices.