同樣一段代碼 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條經(jīng)驗 獲得超11個贊
上下兩個長度都不一樣 receive_arr[1024 ] 和 new unsigned short(1024); 仔細看下 new的用法 ,怎么new數(shù)組
- 2 回答
- 0 關(guān)注
- 1338 瀏覽
添加回答
舉報
0/150
提交
取消