求助:为什么读出的数据长度和文件不一致了?

本文探讨了在将文件数据读入Vector后,数据大小不一致的问题,并深入分析了导致此现象的原因,特别关注了二进制数据处理过程中可能遇到的难点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

源代码:

#include <iostream>
#include <vector>
#include <fstream>
#include <windows.h>
using namespace std;

int main()
{
vector<unsigned char> bvec;
unsigned char temp;
fstream file("D:\\a48s.EP",fstream::ate|fstream::in|fstream::out|fstream::binary);
if (!file)
{
cerr<<"error:unable to open the file."<<endl;
return 0;
}
fstream::pos_type end_mark=file.tellg();
    fstream::pos_type mark;
file.seekg(0,ios::beg);
    while (file.tellg()!=end_mark)
{
        mark=file.tellg();
file>>temp;
bvec.push_back(temp);
}
    vector<unsigned char>::size_type length=bvec.size();
return 0;
}

把一个文件读到Vector后,发现读出的数据和实际问价大小不一致,不知道什么原因?其中好像碰到二进制0c 00 就没有读到vector中,求解释。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值