我正在进行作业"文本文件压缩"使用按位运算符。我不知道为什么它不读取整个文件(压缩文本文件)。虽然简单的文本文件读得很好,为什么会这样?
int main()
{
ifstream inFile;
inFile.open("Compressed.txt");
int counter = 0;
inFile.seekg (0, inFile.end);
int length = inFile.tellg();
inFile.seekg (0, inFile.beg);
cout << "The real file size: " << length << "\n\n\n";
while(!inFile.eof())
{
char ch;
inFile.get(ch);
counter ++;
}
inFile.close();
cout << endl <<"Number of characters read before eof: "<< counter;
counter = 0;
inFile.open("Compressed.txt", ios_base::binary);
while(!inFile.eof())
{
char ch;
inFile.get(ch);
counter ++;
}
inFile.close();
cout << endl <<"Number of characters read before eof as a binary stream: "<< counter << endl << endl;
}