Hi. My problem is that i am trying to read in data in blocks. but i want to make sure i'm not reading past end of the files. so i am trying to detect eof
my code started as this
Code:
int ReadToBuf(char *buffer, int Amount, fstream &Stream)
{
int AmountRead = 0;
char CharBuf;
if (Stream.is_open())
{
cout<<"File is open\n";
while ( (AmountRead < Amount - 1) )
{
Stream.get(CharBuf);// (CharBuf, 1);
buffer[AmountRead] = CharBuf;
AmountRead++;
}
return AmountRead;
}
return -1;
}
Then in an attemp to detect EOF i did
Code:
int ReadToBuf(char *buffer, int Amount, fstream &Stream)
{
int AmountRead = 0;
char CharBuf;
if (Stream.is_open())
{
cout<<"File is open\n";
while ( (AmountRead < Amount - 1) && ( !(Stream.rdstate() & ios_base::eofbit) != 0) )
{
Stream.get(CharBuf);// (CharBuf, 1);
buffer[AmountRead] = CharBuf;
AmountRead++;
}
return AmountRead;
}
return -1;
}
In my attemp to fix, it can no longer read data, so i'm wondering how to detect that i have reached EOF. i've looked over fstream's class declaration and its ancestors, the function eof() didn't work either.