写日志

先获取进程所在路径,然后创建文本文件,写入日志,保存到该目录

可以把需要的信息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);
	
}


猜你喜欢

转载自blog.csdn.net/qq_24282081/article/details/79929774