c语言遍历字节,c-istream_iterator遍历二进制文件中的字节

给定一个包含以下十六进制代码的文件:0B 00 00 00 00 00 20 41

我正在尝试填充std :: vector< std :: uint8_t>然后手动检查每个字节.

这是我使用迭代器构造函数从两个std :: istream_iterators创建向量的代码

using Bytes = std::vector<:uint8_t>;

using ByteItr = std::istream_iterator<:uint8_t>;

Bytes getBytes()

{

std::ifstream in;

in.open("filepath");

in.seekg(0, std::ios::beg);

Bytes bytes;

ByteItr start(in);

ByteItr end;

return Bytes(start, end);

}

这是我试图通过的单元测试:

auto bytes = getBytes();

REQUIRE( bytes.size() == 8 );

CHECK( bytes[0] == 0x0B );

CHECK( bytes[1] == 0x00 );

CHECK( bytes[2] == 0x00 );

CHECK( bytes[3] == 0x00 );

CHECK( bytes[4] == 0x00 );

CHECK( bytes[5] == 0x00 );

CHECK( bytes[6] == 0x20 );

CHECK( bytes[7] == 0x41 );

为什么在这种情况下,它跳过两个元素并隐式将我的std :: uint8_t向量转换为无符号字符?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值