0
在試圖讀取PCAP的全局文件頭,使用主代碼:ifstream的不讀就想值
int main()
{
std::ifstream in("test.pcap", std::ifstream::in | std::ifstream::binary);
pcap_header gheader(in);
in.close();
return 0;
}
及以下gheader構造:
pcap_header::pcap_header(std::ifstream& in)
{
in >> magic_number;
in >> version_major;
in >> version_minor;
in >> thiszone;
in >> sigfigs;
in >> snaplen;
in >> network;
// debug
std::cout << std::hex << magic_number << " " << version_major << " " << version_minor << " " << thiszone << " " << sigfigs << " " << snaplen<< " " << network << std::endl;
}
返回的輸出而不是
0 ffcc 28 75b97220 38369fae fffffffe 75b8413a
:
a1b2c3d4 2 4 0 0 40000 1
thx,我可以使用in.read()讀入非char *變量嗎? –
是的,在讀取二進制數據時,您需要使用'read()'而不是'operator >>'。 'operator >>'只適用於格式化文本。 –