简单C++ log 类

来源:互联网 发布:如何开发聊天软件 编辑:程序博客网 时间:2024/06/05 18:05
class CSimpleLog
{
public:
CSimpleLog( char * strLogFileName )
{
if ( strLogFileName && strlen(m_strLogFileName) )
{
strcpy( m_strLogFileName, strLogFileName );
}




m_fLog = fopen( strLogFileName, "w+b" );




}


~CSimpleLog()
{
if (m_fLog)
{
fclose(m_fLog);
m_fLog=NULL;
}
}


private:


char m_strLogFileName[200];


FILE * m_fLog;


public:


void writeLog( char * pstrLog )
{
if (m_fLog)
{
fwrite( pstrLog, 1, strlen(pstrLog), m_fLog );
fwrite("\r\n",1,2,m_fLog);


fflush( m_fLog );
}
}




};
0 0
原创粉丝点击