c++建立資料夾及其中的檔案
阿新 • • 發佈:2019-01-04
程式碼展示
#include <iostream>
#include <direct.h>
#include <fstream>
#include <io.h>
using namespace std;
int main()
{
if (_access(".\\testtmp", 0) == -1)/////資料夾不存在時候
{
cout << "資料夾不存在的時候" << endl;
if (_mkdir(".\\testtmp") == 0)
{
system("dir .\\testtmp" );
ofstream out_file;
out_file.open("testtmp\\1.txt");
out_file << "你在幹嘛呢????" << endl;
out_file.close();
system("dir .\\testtmp");
}
}
else////////資料夾存在的時候
{
cout << "資料夾存在的時候" << endl;
system("dir .\\testtmp" );
ofstream out_file;
out_file.open("testtmp\\2.txt");
out_file << "你在幹嘛呢????" << endl;
out_file.close();
system("dir .\\testtmp");
}
system("pause");
return 0;
}