So I've been coding a program that uses a binary file. In the program though, I want it to check if the file is empty. I've been searching, and found a solution that seemed promising, however, I'm getting an error "more than one operator "==" matches these operands." Here is my pseudo code:
struct stat info;
int ret = stat("file.dat", &info);
if (ret == -1)
std::cout << "File does not exist" << std::endl;
std::cout << "File size is: " << info.st_size << " bytes" << std::endl;
The idea is, opening a file is one of the most expensive things you can do locally on a computer. stat() checks the metadata for the file and so doesn't update the file or metadata (last access time for example), and so is faster, simpler, more efficient and has no side effects.
Please don't open a file just to check it's size or existence.