//日志函数
//.h文件
int WriteLog(const char* fmt, ...);
//.cpp文件
#include <string>
#include <stdio.h>
#include <tchar.h>
using namespace std;
......
int WriteLog(const char * fmt, ...)
{
char Logbuffer[300];
va_list aptr;
int ret;
va_start(aptr, fmt);
ret = vsprintf(Logbuffer, fmt, aptr);
char buffer[MAX_PATH];
GetCurrentDirectoryA(MAX_PATH, buffer);//当前文件路径
string logpath = (string)"E:\\aLog.log";//日志文件位置 根据需求定义
FILE *pFile;
pFile = fopen(logpath.c_str(), "a+");
time_t t = time(0);
char tmp[64];
strftime(tmp, sizeof(tmp), "%Y.%m.%d %X", localtime((&t)));
string timeStr = tmp;
fprintf(pFile, "[%s] : %s\n", timeStr.c_str(), Logbuffer);
fclose(pFile);
va_end(aptr);
return 0;
}