您的位置:首页 > 其它

CStdioFile类建立日志记录文件

2016-05-28 12:16 357 查看
1,CStdioFile类建立日志文件,定义全局变量,每个需要记录位置的地方,以当前时间作为文件名称;

在C**App类的初始化函数 InitInstance() 建立日志文件,日志文件路径是当前目录下建立Log文件夹

//log text 全局变量
CStdioFile g_logFile;
//日志文件
CString filename;
CTime tm = CTime::GetCurrentTime();
filename = tm.Format(L"%Y%m%d_%H%M%S.txt");
char pCurPath[100];
GetCurrentDirectoryA( 100, pCurPath );
filename = CString(pCurPath) + L"\\Log\\" + filename;
g_logFile.Open( filename,CFile::modeCreate|CFile::modeWrite );
2,CStdioFile 默认情况下不能打印汉字,需要添加一行代码
//非常关键,允许打印汉字
setlocale(LC_CTYPE,"chs");


3,每个记录处,记录当前时间和需要的内容
CString strLog;
CTime tm = CTime::GetCurrentTime();
strLog = tm.Format(L"\n\n%Y\\%m\\%d %H:%M:%S");
g_logFile.WriteString( strLog );
g_logFile.WriteString(L"\n程序启动!");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: