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<好了这篇文章就介绍到这了,需要的朋友可以的参考一下。
热门推荐
1 训练狗狗搜寻
2 如何训练狗狗装死
3 狗狗训练书
6 怎么训练狗狗拜年
8 狗狗训练游戏
10 狗狗嗅觉训练
11 怎么训练狗狗在笼子里不叫
12 怎么训练狗狗站立走路
13 怎么训练狗狗在马桶上
14 狗狗尿尿怎么训练
15 训练狗狗用品
16 泰迪狗狗的训练方法大小便
17 训练狗狗可以打吗
18 王曼丽的狗狗训练