清空文件可以使用系统调用truncate: #include <unistd.h> #include <sys/types.h> int main() { truncate("to_clean_file.txt", 0); return 0; }