[英]ifstream doesn't read wanted values
In an attempt to read a pcap's global file header, using the main code: 为了尝试使用主代码读取pcap的全局文件头,请执行以下操作:
int main()
{
std::ifstream in("test.pcap", std::ifstream::in | std::ifstream::binary);
pcap_header gheader(in);
in.close();
return 0;
}
and the following gheader constructor: 和以下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;
}
the returned output is: 返回的输出是:
0 ffcc 28 75b97220 38369fae fffffffe 75b8413a
instead of: 代替:
a1b2c3d4 2 4 0 0 40000 1
Looks like you're opening the file as binary: std::ifstream::binary
but then reading like it's a text file. 看起来您正在以二进制文件形式打开文件:
std::ifstream::binary
,然后像文本文件一样读取文件。 If it's a text file then remove std::ifstream::binary
. 如果是文本文件,则删除
std::ifstream::binary
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.