|
log.h
#ifndef _LOG_H
#define _LOG_H
#include <iostream>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LOG_FILE "log.bin"
using namespace std;
/*日志打印类
*
*/
class log
{
public:
~log(void);
void creat_log(string str, string filename, unsigned int row);
const char *basename (const char *filename);
static log *get_log_instance()
{
if (m_log == NULL)
{
m_log = new log();
}
return m_log;
}
void release()
{
if (m_log != NULL)
{
delete m_log;
}
}
private:
log(void);
private:
FILE* m_hFile;
static log *m_log;
};
#endif // _LOG_H
log.cpp文件
#include "log.h"
log* log::m_log = NULL;
log::log(void)
{
m_hFile = fopen(LOG_FILE, "a+");
}
log::~log(void)
{
fclose(m_hFile);
}
const char *log::basename(const char *filename)
{
const char *p = strrchr(filename, '\\');
return p ? p + 1 : (char *) filename;
}
void log::creat_log(string str, string filename, unsigned int row)
{
if (m_hFile != NULL)
{
time_t timep;
struct tm *p;
time(&timep);
p = localtime(&timep); //取得当地时间
char buff[2048] = {0};
printf("test");
fwrite(buff, strlen(buff), 1, m_hFile);
fflush(m_hFile);
}
}
出现错误: log.cpp:3: syntax error before `*' token |
|