1

I am trying to load data from file when program loads,but i need to detect first wether the is file is empty or not ? When it loads it makes program infinite, so how can i detect a empty file in c++?

void loadfromfile(record *&newrecord, ifstream &in)
{
    in.open("records.txt", ios::binary | ios::in);
    record *temprecord = new record;
    record *tempreholder = new record;
    tempreholder = newrecord;
    while (!in.eof())
    {
        if (newrecord == nullptr)
        {
            newrecord = new record;
            in.read((char *)(&newrecord), sizeof(newrecord));
            newrecord->node = nullptr;
        }
        else
        {
            in.read((char *)(&temprecord), sizeof(temprecord));
            temprecord->node = nullptr;
            newrecord->node = temprecord;
        }
    }
    newrecord = tempreholder;
    in.close();
}
MacGruber
  • 162
  • 2
  • 13
equiNoX
  • 11
  • 1

0 Answers0