C ++无法读取整个文件

时间:2017-10-18 18:02:25

标签: c++ file

我正在进行作业"文本文件压缩"使用按位运算符。我不知道为什么它不读取整个文件(压缩文本文件)。虽然简单的文本文件读得很好,为什么会这样?

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;
}

0 个答案:

没有答案