0

how can i check if my text file is empty???
i have tried something using eof but it doesnt seem to work or am just using it wrongly

if(infile.eof())//check if it is empty
/*also tried this*/ if(infile.eof()==0)
3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Radical Edward
0

> how can i check if my text file is empty???
Try to read from it. If the read fails with eofbit set, the file is empty:

bool IsEmpty(std::istream& is)
{
  char ch;

  is.get(ch);

  return is.eof();
}

Remember that eof() only returns true after a failed input request.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.