By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,925 Members | 1,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,925 IT Pros & Developers. It's quick & easy.

Error in compilation of C++ file with drent.h

P: 6
Hi all, I am new to the VC++. I am stuck in trying to compile my read directory codes in C++. It keeps giving me this error:
Error 1 fatal error C1083: Cannot open include file: 'dirent.h': No such file or directory

Hope that there will be a solution to this. Many thanks.
Dec 20 '06 #1
Share this Question
Share on Google+
7 Replies


Banfa
Expert Mod 5K+
P: 8,916
dirent.h is not a standard header so I assume it is one you have created. Is it in the same directory as your C/C++ source? If not have you provide the compiler with the correct path to it?
Dec 20 '06 #2

Ganon11
Expert 2.5K+
P: 3,652
In your #include statements, are you trying to include "dirent.h"? If you are, you may have a spelling error keeping your program from finding the directory - either that, or the header file is not in the same folder as your main program.
Dec 20 '06 #3

P: 6
dirent.h is not a standard header so I assume it is one you have created. Is it in the same directory as your C/C++ source? If not have you provide the compiler with the correct path to it?
Ya. I had put it in the same folder as the source file. I also added into the same project as of the source file too.
Dec 20 '06 #4

Banfa
Expert Mod 5K+
P: 8,916
Well then I would guess at a coding error, car to post the piece of coding exhibiting the error.
Dec 20 '06 #5

P: 6
Well then I would guess at a coding error, car to post the piece of coding exhibiting the error.
the whole code is as of below.

#include <sys/types.h>
#include <cstdlib>
#include <stdio.h>
#include <dirent.h>
#include <dir.h>
#include <errno.h>
#include <vector>
#include <string>
#include <iostream>
#include <fstream>

using namespace std;

/*function... might want it in some class?*/
int getdir (string dir, vector<string> &files)
{
DIR *dp;
struct dirent *dirp;
if((dp = opendir(dir.c_str())) == NULL) {
cout << "Error(" << errno << ") opening " << dir << endl;
return errno;
}

while ((dirp = readdir(dp)) != NULL) {
files.push_back(string(dirp->d_name));
}
closedir(dp);
return 0;
}

int main()
{
string dir = string(".");
vector<string> files = vector<string>();

getdir(dir,files);

for (unsigned int i = 0;i < files.size();i++) {
cout << files[i] << endl;
}
return 0;
}



the error msg is as of:

Error 1 fatal error C1083: Cannot open include file: 'dirent.h': No such file or directory
Dec 20 '06 #6

Ganon11
Expert 2.5K+
P: 3,652
Try replacing

#include <dirent.h>

with

#include "dirent.h"

In my compiler (Bloodshed DevC++ 4.9.9.2), when including a header file defined by the programmer, it must be included with quotation marks instead of braces.
Dec 20 '06 #7

Banfa
Expert Mod 5K+
P: 8,916
In my compiler (Bloodshed DevC++ 4.9.9.2), when including a header file defined by the programmer, it must be included with quotation marks instead of braces.
because < and > specifically instruct the compiler to not look in the directory the source code is in. They should only be used for standard library headers.
Dec 20 '06 #8

Post your reply

Sign in to post your reply or Sign up for a free account.