我想使用Cpp读取二进制文件,其类型使用MsgPack。 我不熟悉MsgPack,我尝试阅读二进制文件拳头并推入MsgPack。它不起作用。它只是一次又一次地得到第一个数字。谁能帮忙?非常感谢。在C++中使用MsgPack读取二进制文件
#include <bits/stdc++.h>
#include <msgpack.hpp>
using namespace std;
int main()
{
std::ifstream ifs("input.txt", std::ifstream::in);
std::stringstream buffer;
buffer << ifs.rdbuf();
msgpack::unpacked upd;
msgpack::unpack(upd, buffer.str().data(), buffer.str().size());
std::cout << upd.get() << std::endl;
return 0;
}
它只能得到第一个数字“3”。
,我希望能得到数:
3
[3 6 7 5 3 5]
[6 2 9 1 2 7]
[0 9 3 6 0 6]
而且here是输入的二进制文件。
您的解决方案基于您的假设,第一个数字是以下数组的数目。如果这是不正确的,@Gavin Lee只是想解析4条独立消息?至少你可以在for循环中检查'offset'是否仍然小于'buffer.size()'。 – JustRufus