简单的文件读写,自己写了下,做日志保存用。 void CFilewriteDlg::OnButton1() { // TODO: Add your control notification handler code here WIN32_FIND_DATA fd; BOOL ret = FALSE; HANDLE hFind = FindFirstFile("log", &fd); if ((hFind != INVALID_HANDLE_VALUE) && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { //目录存在 FindClose(hFind); ret = TRUE; } else { CreateDirectory("log", NULL); } CFile theFile; CString strFile = "log//test.log"; CFileStatus status; BOOL bOpenOK = FALSE; if(CFile::GetStatus(strFile, status)) { bOpenOK = theFile.Open(strFile, CFile::modeWrite); } else { bOpenOK = theFile.Open(strFile, CFile::modeCreate | CFile::modeWrite); } //CFile file("CFile.txt",CFile::modeCreate | CFile::modeWrite); //file.SeekToEnd(); /*file.Write("teshorse@hotmail.con/r/n", strlen("teshorse@hotmail.com/r/n")); file.Write("teshorse@hotmail.con/r/n", strlen("teshorse@hotmail.com/r/n")); file.Flush(); file.Close();*/ CTime time = CTime::GetCurrentTime(); CString strTime = time.Format("[%Y-%B-%d-%H-%M-%S]/t"); theFile.SeekToEnd(); theFile.Write(strTime, strTime.GetLength()); theFile.Write("---------日志记录----------/r/n", strlen("---------日志记录----------/r/n")); theFile.Write(strTime, strTime.GetLength()); theFile.Write("文件出错!/r/n", strlen("文件出错!/r/n")); theFile.Flush(); theFile.Close(); }