如何将日志写入大小为64KB的文件(允许记事本读取).一旦文件达到64KB,它应该开头创建另一个,另一个......文件名可以自动生成.
我尝试了以下代码
static int iCounter=1;
CString temp;
static CStdioFile f(L"c:\\Log1.txt", CFile::modeWrite | CFile::modeRead | CFile::modeCreate | CFile::modeNoTruncate);
int nlength = (int)f.GetLength();
if(nlength>(nMaxFileSize*1024))
{
//need to create a new file
f.Close();
iCounter++;
temp.Format(_T("%s%d%s"), "c:\\Log",iCounter, ".txt");
f.Open(temp,CFile::modeWrite | CFile::modeRead | CFile::modeCreate | CFile::modeNoTruncate);
}
f.SeekToEnd();
f.WriteString(str);
f.WriteString(L"\r\n");
Run Code Online (Sandbox Code Playgroud)
我正在寻找一个更好的选择.