#include <fstream>
void Log(string filePath, string fileName, string way, string content)
{
FILE *fp;
if(0 != _access(filePath.c_str(),0)) {
CreateDir(filePath);
}
string fullPath = filePath + “\\” + fileName;
fopen_s(&fp, fullPath.c_str(), way.c_str());
fprintf(fp, content.c_str());
fclose(fp);
}
举例使用:
void main() {
string str;
Log(“D:\\Log\\20200202”, “test.log”,”at”, str);
}