struct dirnet定义
刚开始学习linux下编程,搭建了开发环境,抄了一小段代码,可就是编译不过,
- C/C++ code
#include <iostream>#include <stdio.h>#include <unistd.h>#include <sys/stat.h>#include <sys/types.h>#include <dirent.h>using namespace std;int main(){ DIR *dp; struct dirnet *dirp; if((dp = opendir("/work"))== NULL) { cout << "can't open /work" << endl; } while((dirp = readdir(dp)) != NULL) { printf("%s\n", dirp->d_name); } cout << "Hello World!" << endl; return 0;}可就是编译不过,错误为
cannot convert 'dirnet *' to 'dirnet *' in assignment;
invalid use of incomplete type 'struct dirnet';
forward declaration of 'struct dirnet';
我发现系统中有/usr/include/dirnet.h 和/usr/include/bits/dirnet.h两个头文件,dirnet结构体是在后一个
头文件中定义的 ,但是不能include后一个头文件。熟悉的给讲解下呀!
[解决办法]
#include <bits/dirnet.h>
[解决办法]
你写错了吧
struct dirnet *dirp; ==> struct dirent *dirp;