CStdioFile类建立日志记录文件
2016-05-28 12:16
357 查看
1,CStdioFile类建立日志文件,定义全局变量,每个需要记录位置的地方,以当前时间作为文件名称;
在C**App类的初始化函数 InitInstance() 建立日志文件,日志文件路径是当前目录下建立Log文件夹
//log text 全局变量
CStdioFile g_logFile;
//非常关键,允许打印汉字
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程序启动!");
在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程序启动!");
相关文章推荐
- 2.1.4 uboot的工作方式
- 修改源码,自定义chromium启动页
- ie调试器
- 3611: [Heoi2014]大工程
- 勺子难免碰锅沿,不咬舌怎么读θ和ð?
- 2.1.3 uboot必须解决哪些问题?
- LeetCode:Count Primes
- Sublime Text 使用技巧
- ava包装类型的MAX_VALUE到底是多少啊
- Web服务器安全设置
- 2.1.2 93b6 为什么是uboot?
- shell 脚本(menu)
- php自定义中文字符串截取函数substr_for_gb2312及substr_for_utf8示例
- C#中的访问修饰符
- 笔试题68. LeetCode OJ (55)
- Bridge(桥接)-对象结构型模式
- error inflating class binaryXML LayoutParams addRule()
- Android面试题大集结
- PowerShell 查询 Excel记录
- Delphi XE10.1 引用计数