通过本文主要向大家介绍了c c++ c#区别,c和c++的区别,c语言和c++有什么区别,c/c++,c语言与c++的区别等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
1.数据结构
typedef struct __dirstream DIR;
</div>
2.程序示例
其中程序中win不支持文件类型(d_type),可以根据文件名称后缀来判断文件类型;linux可以直接使用d_type判断是目录还是文件。
int main(){
DIR *dir;
struct dirent *ptr;
dir = opendir("."); ///open the dir
while((ptr = readdir(dir)) != NULL) ///read the list of this dir
{
#ifdef _WIN32
printf("d_name: %s\n", ptr->d_name);
#endif
#ifdef __linux
printf("d_type:%d d_name: %s\n", ptr->d_type,ptr->d_name);
#endif
}
closedir(dir);
return 0;
}
</div>
程序输出: