LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 911|回复: 2

写了一个单实例类,在windows下能编译通过,为什么在linux编译不过

[复制链接]
发表于 2009-9-9 13:02:40 | 显示全部楼层 |阅读模式
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
发表于 2009-9-9 19:22:49 | 显示全部楼层
文件编码问题?
你是在什么环境下写的程序?win 下?
回复 支持 反对

使用道具 举报

发表于 2009-9-22 09:12:34 | 显示全部楼层
strrchr(filename, '\\');
字符可以这么表示?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表