在 Debian(以及其他 Linux 发行版)上使用 opendir 函数时,是需要包含头文件的。
opendir 是 POSIX 标准中的目录操作函数,声明在:
#include <dirent.h>
#include <stdio.h>
#include <dirent.h>
int main() {
DIR *dir = opendir(".");
if (dir == NULL) {
perror("opendir");
return 1;
}
closedir(dir);
return 0;
}
在 Debian 上通常使用 gcc:
gcc test.c -o test
opendir 返回 DIR *readdir, closedir, rewinddir 也都在 <dirent.h> 中如果你是在写 C++,同样需要:
#include <dirent.h>
如果你指的是 其他语言或环境(如 Python、Rust、Shell),可以告诉我,我可以分别说明。