C++创建文件夹

使用 system()

#include <iostrem>
using namespace std;

int main()
{
    string defaultPath = "E:\\database";
    string folderPath = defaultPath + "\\testFolder"; 
    string command;
    command = "mkdir -p " + folderPath;  
    system(command.c_str());
    return 0;
}

使用头文件 direct.h 中的 access 和 mkdir 函数

#include <direct.h>
#include <iostrem>
using namespace std;

int main()
{
    string defaultPath = "E:\\database";
    string folderPath = defaultPath + "\\testFolder";
    if (0 != access(folderPath.c_str(), 0))
    {
        // if this folder not exist, create a new one.
        mkdir(folderPath.c_str());   // 返回 0 表示创建成功,-1 表示失败
      }
   return 0;
}

原文:https://blog.csdn.net/sinat_41104353/article/details/83149441

猜你喜欢

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