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)

Recommended Answers

All 2 Replies

> 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.