i have created one method to write to Log file but each time it overrite the log details , i want to create a new entry everytime for logging details.My log method is as below :
void CNDSConnectDlg::WriteLogData()
{
CString strUserName = "";
m_editUserName.GetWindowText(strUserName);
FILE * pFile = NULL;
int iErr = 0;
iErr = fopen_s(&pFile,"NDSLog.txt","w");
if (iErr == 0)
{
CString strConnectionStatus = "";
CString strServerAddress = "";
CString strDateTime = "";
SYSTEMTIME systime;
GetLocalTime(&systime);
if(m_bConnectionStaus == true)
{
strConnectionStatus = "Success";
}
else
{
strConnectionStatus = "Failure";
}
strUserName.Format("%s",strUserName);
strConnectionStatus.Format("%s",strConnectionStatus);
strServerAddress.Format("%s",m_strIPAddress);
strDateTime.Format("%i:%i:%i\\%02i-%02i-%02i",
systime.wHour,
systime.wMinute,
systime.wSecond,
systime.wYear,
systime.wMonth,
systime.wDay);
fputs("UserName = " + strUserName + " connected to "
"ServerAddress = " +strServerAddress + " at "
"Date/Time = " + strDateTime + " "
"ConnectionStatus = " +strConnectionStatus + " ",pFile);
fclose (pFile);
}
else
{
MessageBox("Error in writing to Log","NDS",MB_ICONERROR | MB_OK);
}
}
Any help is highly appreciated . Thanks in Advance.
用“ a”(附加)而不是“ w”打开文件。
用打开文件a+
,而不是a
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.