同样一段代码 FILE *fpf = fopen(filePath, "rb");
fseek(fpf, 98, SEEK_CUR);
unsigned short int receive_arr[1024] = { 0 };
fread((char*)&receive_arr, sizeof(receive_arr), 1, fpf);
int tmp_count = 0;
for (auto value : receive_arr)cout << "count: " << ++tmp_count << " value: " << value << endl;就是正确的而使用C++ 的fstream: fstream fpf(filePath, ios::binary);
unsigned short* receive_arr = nullptr;
try
{
receive_arr = new unsigned short(1024);
}
catch (bad_alloc)
{
cerr << "bad_alloc in" << __LINE__ << endl;
}
fpf.seekg(sizeof(char) * 98,ios_base::beg);
fpf.read((char*)receive_arr,2048);
fpf.close();读出来的receive_arr的值就是不对的,这是为什么?
2 回答
慕盖茨4494581
TA贡献1850条经验 获得超11个赞
上下两个长度都不一样 receive_arr[1024 ] 和 new unsigned short(1024); 仔细看下 new的用法 ,怎么new数组
- 2 回答
- 0 关注
- 1317 浏览
添加回答
举报
0/150
提交
取消