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

时间:2024-04-08 21:35:50

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 = "";
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;
}
}
}