先获取进程所在路径,然后创建文本文件,写入日志,保存到该目录
可以把需要的信息Format进CString,再写入日志
void WriteLogText(CString m_cstrLogContent) { CString strFileName; GetModuleFileName(AfxGetInstanceHandle(),strFileName.GetBuffer(_MAX_PATH),__MAX_PATH); strFileName.ReleaseBuffer(); strFileName = strFileName.Left(strFileName.ReverseFind('\\') + 1); CString cstrLogFilePath = strFileName + "MyLogName.log"; FILE* pLogFileObj = fopen(cstrLogFilePath,"a+"); fprintf(pLogFileObj,"%s",m_cstrLogContent); fclose(pLogFileObj); }