C++ 判断目录文件是否存在

//判断目录文件是否存在
#include <iostream>
#include <dirent.h>
#include <string>

using namespace std;

int main()
{

    std::string name;
    std::string path = "./" + name;
    auto dir = opendir(path.data());
    if(dir == NULL)
        std::cout << "目录不存在" << std::endl;
    else {
        std::cout << "目录存在" << std::endl;
    }
    closedir(dir);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42439026/article/details/88787966