Checking for an empty file in C++

前端 未结 8 2030
抹茶落季
抹茶落季 2020-11-27 03:35

Is there an easy way to check if a file is empty. Like if you are passing a file to a function and you realize it\'s empty, then you close it right away? Thanks.

E

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 03:57

    if (nfile.eof()) // Prompt data from the Priming read:
        nfile >> CODE >> QTY >> PRICE;
    else
    {
        /*used to check that the file is not empty*/
        ofile << "empty file!!" << endl;
        return 1;
    }
    

提交回复
热议问题