[英]Using binary file to deal with compressed data
我有這段代碼處理文件以保存壓縮值,然后讀取壓縮文件以解壓縮它,這樣它工作得很好:這只是我代碼的一部分:
void func1(){
unsigned int const Qsz = 5 * NRB+15;
unsigned char Qchar[Qsz]; // this array has the compressed values after compreesion
ofstream Resfile;
Resfile.open("C://Compressedfile.fr", ios::binary | ios::out);
Resfile.write((char *)Qchar, (Qsz) * sizeof(char));
Resfile.close();
}
void func2(){
ifstream Resfile;
Resfile.open("C://Compressedfile.fr", ios::binary | ios::in);
unsigned char NRBst[2];
Resfile.read((char *)NRBst, 2 * sizeof(char));
unsigned int const Qsz = (5 * NRB)+13;
unsigned char Qchar[Qsz];
Resfile.read((char*)Qchar, Qsz * sizeof(char));
Resfile.close();
}
我想知道這是什么意思?
unsigned char NRBst[2];
Resfile.read((char *)NRBst, 2 * sizeof(char));
為什么當我評論它時,代碼給了我一個錯誤的結果? 請注意,它沒有在代碼的其他任何地方使用!
第一次更新
unsigned int const Qsz = 5 * NRB+15;
unsigned char Qchar[Qsz]; // this array has the compressed values
void func1(){
// Here, there are some processing on my data to get on compressed data
// and then save it in Qchar[Qsz]
Qchar[Qsz];
}
void func2(){
//unsigned char NRBst[2];
//Resfile.read((char *)NRBst, 2 * sizeof(char));
unsigned int const Qsz1 = (5 * NRB)+13;
Qchar[Qsz1];
}
讀取行從傳入的 stream 中獲取前 2 個字節,並將它們放入垃圾緩沖區。 如果它沒有在其他任何地方使用,那么它可能是填充或元數據。 當您將其注釋掉時它失敗的原因是因為現在您正在將 stream 的不同部分讀入您的數據然后被解壓縮。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.