C++ 判断目录是否存在并新建目录

http://blog.csdn.net/u012005313/article/details/50688257

#include <io.h>
#include <string>
#include <fstream>
#include <string>
#include <vector>
#include <iostream>
#include <direct.h>  
using namespace std;

int main()
{
        string  cursubdirname = "123";
    if (access(cursubdirname.c_str(), 0) == -1)
    {
        cout << cursubdirname << " is not existing" << endl;
        cout << "now make it" << endl;
#ifdef WIN32  
        int flag = _mkdir(cursubdirname.c_str());
#endif  
#ifdef linux   
        int flag = mkdir(dir.c_str(), 0777);
#endif  
        if (flag == 0)
        {
            cout << "make successfully" << endl;
        }
        else {
            cout << "make errorly" << endl;
        }
    }
}

 

posted on 2018-02-27 18:17  Maddock  阅读(1523)  评论(0编辑  收藏  举报

导航