2011-04-03 91 views
34

我想用在我的代碼#include<dirent.h>,但這個錯誤發生:<dirent.h>在Visual Studio 2010或2008

無法打開包含文件: 'dirent.h':沒有這樣的文件或目錄

我該如何解決這個問題?

+0

它與* nix綁定太重了。在Windows上使用_findfirst/_findnext來迭代目錄,'#include ' – 2011-04-03 17:32:52

+0

可能重複[#include ](http://stackoverflow.com/questions/2228656/includedirent-h) – sdgfsdh 2016-06-30 12:26:05

回答

48

因爲此頭文件不附帶MSVC。因此它找不到它!

它自帶C POSIX庫。該wikipedia說,

dirent.h知道要包含在 以下編譯器:

  • 的Turbo C++(DOS)
  • GCC(跨平臺)
  • MinGW的(微軟Windows)
  • Borland C++ Builder(Microsoft Windows)

微軟的Visual C++不包括 dirent.h

但是,你可以下載free Windows implementation of dirent.h,你可以使用Microsoft Visual Studio中使用。

+0

如何在visual studio中使用它? – woody 2011-04-03 16:48:28

+0

@woody:這個網站解釋說:http://www.softagalleria.net/dirent.php – Nawaz 2011-04-03 16:49:33

+1

針對windows的dirent的最新版本(2012年4月)有bug,我現在正在使用第一個版本(2006)。 第一個版本的來源:https://svn.apache.org/repos/asf/avro/trunk/lang/c/tests/msdirent.h – anilbey 2014-08-07 17:00:48

2

This is another light-weight dirent.h implementation for Windows。這是兩個文件,您可以直接放入。

目前,在Windows上獲取完整POSIX支持的最佳方式大概是Cygwin or its friends

Windows Services for UNIX(SfU),但是according to some與Cygwin在2006年非常接近。看到Cygwin及其一些同志生活得很好,而且SfU在過去的五年中沒有看到更新,我會選擇前一天的任何一天。

如果您對過去的爆炸感興趣,請檢查this little nugget from 2006這是微軟的官方如何從UNIX端口到Windows網站。這看起來相當無用,但有趣的是,微軟在2006年認爲它是「有用的」。