//prepare 在工程当前目录添加一空文档文件,命名为“Log.txt”
//test.h
#define MAX_LENGTH 256
CString m_LogPath;
//test.cpp
char buf[MAX_LENGTH];
GetCurrentDirectory(buf);
m_LogPath.Format(MAX_LENGTH ,buf);
strcat(m_LogPath, "//Log.txt");
/*或者
GetCurrentDirectory(MAX_LENGTH , m_LogPath.GetBuffer(MAX_LENGTH ));
m_LogPath.ReleaseBuf();
m_LogPath += "//Log.txt";
*/
CTime m_LogTime = CTime::GetCurrentTime();
CSting strText;
strText.Format("%s/t%s/t操作名称/r/n","UserName", m_LogTime.Format("%y-%m-%d %H:%M:%S"));
CFile file;
file.Open(m_LogPath, CFile::modeWirte);
file.SeekToEnd();
file.Write(strText,strText.GetLength());
file.Close();