C++ 在 Visual Studio 2005 中不能 #include<dirent.h>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2228656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot #include<dirent.h> in Visual Studio 2005
提问by SHIVA KUMAR
When I include dirent.h
(#include<dirent.h>
) in Visual Studio 2005, I get the error:
当我在 Visual Studio 2005 中包含dirent.h
( #include<dirent.h>
) 时,出现错误:
fatal error C1083: Cannot open include file: 'dirent.h': No such file or directory
致命错误 C1083:无法打开包含文件:“dirent.h”:没有这样的文件或目录
I am new to C++; can anyone please provide me the solution for this error?
我是 C++ 新手;任何人都可以为我提供此错误的解决方案吗?
回答by SHIVA KUMAR
The file dirent.h is not a C++ Standard header file. As you are on Windows, you probably want to use the FindFirstFileand related functions, declared in windows.h
文件 dirent.h 不是 C++ 标准头文件。在 Windows 上,您可能想要使用在 windows.h 中声明的FindFirstFile和相关函数
回答by hanno
回答by Paolo Tedesco
You should add the directory where the file is located to the "additional include folders" in the Visual Studio project properties.
您应该将文件所在的目录添加到 Visual Studio 项目属性中的“其他包含文件夹”。
回答by Pentium10
Try including just dir.h
and if that doesn't work try io.h
尝试只包括在内dir.h
,如果这不起作用,请尝试io.h
#include <errno.h>
#include <iostream>
#include <io.h>
#include <time.h>
using namespace std;
bool canDelete(int timeCreate);
int main() {
struct _finddata_t data;
int handle;
handle = _findfirst("test.txt", &data);
if(handle == -1) {
exit(1);
}
if(canDelete(data.time_create)) {
cout << "Deleting file ...\n\n";
} else {
cout << "File ok.\n\n";
}
}
/**
* @param: the time in seconds that the file was created.
* @return: true if the file was created more than 7 days,
* false otherwise.
**/
bool canDelete(int time_create) {
time_t seconds = time(NULL);
int days = 7;
int max_time = 60 * 60 * 24 * days;
int time_passed = seconds - time_create;
if(time_passed > max_time) {
return true;
} else {
return false;
}
}