C++ 输出Log
C++ MFC
void CTest::WriteLog(CString strLog)
{
CString str;
CTime nowTime = CTime::GetCurrentTime();
CString strTime = nowTime.Format(L"%Y/%m/%d %H:%M:%S");
str = strTime + L" " + strLog + L"\r\n" ;
CStdioFile file;
file.Open(L"d:\\1\\log.txt", CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite);
file.SeekToEnd();
file.WriteString(str);
file.Close();
}
应用:
Void CTest::Fuction()
{
//writelog
long t1 = GetTickCount();
long t2;
CString strLog;
……
//writelog
t2=GetTickCount();
strLog.Format(L"%2d",t2-t1);
strLog = L"Function Name "+ strLog;
WriteLog(strLog);
}
string strLogPath;
//write log
string strLog = string.Empty;
System.Diagnostics.Stopwatch s