C++ Log日志类轻量级支持格式化输出变量实现代码
CLog头代码很简单如果需要的直接Ctrl+C----Ctrl+V即可
#ifndef__CLOG__ #define__CLOG__ #include#include #include #include #include classCLog { public: CLog(); CLog(conststd::stringLogFile); ~CLog(); template staticvoidWriteLog(Tx); //支持格式化输出多参数输出 staticvoidWriteLogFormat(constchar*format,...); private: staticstd::stringGetFilePath(); std::stringm_LogFilePath; staticstd::stringGetSystemTimes(); staticboolIsPathExist(conststd::stringFilePath); }; //支持输出intdouble文本 template voidCLog::WriteLog(Tx) { std::fstreamof(GetFilePath(),std::ios::app); if(!of.is_open())return; of.seekp(std::ios::end);//设置文件指针到文件尾部 of< CLog.cpp
#include"Log.h" CLog::CLog() :m_LogFilePath("") { m_LogFilePath=GetFilePath(); if(IsPathExist(m_LogFilePath)) DeleteFile(m_LogFilePath.c_str()); } CLog::CLog(conststd::stringLogFile) :m_LogFilePath(LogFile) { if(IsPathExist(m_LogFilePath)) DeleteFile(m_LogFilePath.c_str()); } CLog::~CLog() { } voidCLog::WriteLogFormat(constchar*format,...) { va_listarglist; std::stringstrArgData; charszBuffer[0x1024]; ZeroMemory(szBuffer,0x1024); va_start(arglist,format); vsprintf_s(szBuffer,format,arglist); va_end(arglist); strArgData=szBuffer; std::fstreamof(GetFilePath(),std::ios::app); if(!of.is_open())return; of<好了这篇文章就介绍到这了,需要的朋友可以的参考一下。
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短