CLog 头 代码很简单 如果需要的直接Ctrl+C ----Ctrl+V 即可
#ifndef __CLOG__ #define __CLOG__ #include#include #include #include #include class CLog { public: CLog(); CLog(const std::string LogFile); ~CLog(); template static void WriteLog(T x); //支持格式化输出多参数输出 static void WriteLogFormat(const char* format, ...); private: static std::string GetFilePath(); std::string m_LogFilePath; static std::string GetSystemTimes(); static bool IsPathExist(const std::string FilePath); }; //支持输出int double 文本 template void CLog::WriteLog(T x) { std::fstream of(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(const std::string LogFile) :m_LogFilePath(LogFile) { if (IsPathExist(m_LogFilePath)) DeleteFile(m_LogFilePath.c_str()); } CLog::~CLog() { } void CLog::WriteLogFormat(const char* format, ...) { va_list arglist; std::string strArgData; char szBuffer[0x1024]; ZeroMemory(szBuffer, 0x1024); va_start(arglist, format); vsprintf_s(szBuffer, format, arglist); va_end(arglist); strArgData = szBuffer; std::fstream of(GetFilePath(), std::ios::app); if (!of.is_open())return; of <
好了这篇文章就介绍到这了,需要的朋友可以的参考一下。