我想使用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