#include <string>
#include <direct.h>
#include <io.h>
#include <iostream>
#include <fstream>
//不存在则创建目录和文件
int createDirectory(std::string path)
{
int len = path.length();
char tmpDirPath[256] = { 0 };
for (int i = 0; i < len; i++)
{
tmpDirPath[i] = path[i];
if (tmpDirPath[i] == '\\' || tmpDirPath[i] == '/')
{
if (_access(tmpDirPath, 0) == -1)
{
int ret = _mkdir(tmpDirPath);
if (ret == -1) return ret;
}
}
}
return 0;
}
//文件追加内容
bool WriteDataToOneFile(std::string strData,std::string strPath)
{
createDirectory(strPath);
ofstream ofs;
ofs.open(strPath.c_str(), ios::app);
if (!ofs.is_open())
{
return false;
}
ofs << strData << endl;
ofs.close();
return true;
}