I have a class A that has a std::ifstream filestr member. In one of the class functions I test to see if the stream has reached eof.
class A
{
private:
std::ifstream filestr;
public:
int CalcA(unsigned int *top);
}
Then in the cpp file I have
int CalcA(unsigned int *top)
{
int error;
while(true)
{
(this->filestr).read(buffer, bufLength);
if((this->filestr).eof);
{
error = 1;
break;
}
}
return error;
}
I get a compile error
error: argument of type ‘bool (std::basic_ios<char>::)()const’ does not match ‘bool’
Can anyone tell me how to properly use eof? Or any other reasons why I get this error?
eofis a function, so it needs to called like other functions:eof().That said, the reading loop given can be written more correctly (taking into account other possibilities for failure other than end-of-file) without a call to
eof(), but turning the read operation into the loop condition: