要添加到代码中的标题或其他内容,以检测文件夹是否存在

时间:2014-12-21 03:27:29

标签: c++ directory mingw-w64

我搜索测试文件夹是否存在。我在问题中找到了以下代码: Check folder path

bool directory_exists( const std::string &directory )
    {
    if( !directory.empty() )
        {
        if( access(directory.c_str(), 0) == 0 )
            {
            struct stat status;
            stat( directory.c_str(), &status );
            if( status.st_mode & S_IFDIR )
                return true;
            }
        }
     // if any condition fails
    return false;
    }

我有“访问”的搜索代码,但大多数时候我发现了关于mysql的东西,因为访问具有以下含义:s。

我用这一行来编译:

i686-w64-mingw32-g++ -c -O2 -I.-I/usr/win32/include -g  main.cpp -o main.o

错误

main.cpp: In function 'bool directory_exists(const string&)':
main.cpp:111:40: erreur: 'access' was not declared in this scope
main.cpp:114:46: erreur: no matching function for call to 'stat::stat(const char*, stat*)'
main.cpp:114:46: note: candidates are:
In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/wchar.h:380:0,
             from /usr/lib/gcc/i686-w64-mingw32/4.7.3/include/c++/cwchar:46,
             from /usr/lib/gcc/i686-w64-mingw32/4.7.3/include/c++/bits/postypes.h:42,
             from /usr/lib/gcc/i686-w64-mingw32/4.7.3/include/c++/iosfwd:42,
             from /usr/lib/gcc/i686-w64-mingw32/4.7.3/include/c++/ios:39,
             from /usr/lib/gcc/i686-w64-mingw32/4.7.3/include/c++/ostream:40,
             from /usr/lib/gcc/i686-w64-mingw32/4.7.3/include/c++/iostream:40,

我想我必须添加一些东西。一个标题?

1 个答案:

答案 0 :(得分:1)

您似乎缺少以下2个标题:

#include <sys/stat.h>
#include <dirent.h>