#include <iostream>
#include <sys/stat.h>
bool file_is_empty(std::string &file_path)
{
struct stat buf{};
stat(file_path.c_str(), &buf);
size_t size = buf.st_size;
return size == 0;
}
int main()
{
std::string file_path = "/home/dennis/IsEmpty.txt";
if (file_is_empty(file_path))
std::cout << file_path << " is empty\n";
else
std::cout << file_path << " is not empty\n";
return 0;
}
C++ Linux 判断文件是否为空
最新推荐文章于 2024-02-27 23:30:25 发布