写一个log的功能:
1、把string写到文件中,最好可以带格式化的
   像String的Format一样
2、分等级来写log,你一、二、三、四,我们可以通过定义宏来控制写到几级

解决方案 »

  1.   

    使用xml文件格式可满足你全部要求.
      

  2.   

    自己定义log文件的格式,然后写文件就行了
      

  3.   

    有很多这样的log日志工具类可以参考,不建议用在宏中使用字符串,这样容易引起隐含意外错误
      

  4.   

    也许,可能,楼主是要这么个东西吧(至于分级,自己加个参数就行了)://debuger.h#define DEBUGER_MAX_STRING_LENGTH 1024#include <stdio.h>static void DPrintf(const char * pszCategory,const char * szText,...)
    {
    char static_DebugerTmpBuffer[DEBUGER_MAX_STRING_LENGTH];//供临时用的缓冲区
    memset(static_DebugerTmpBuffer,0,DEBUGER_MAX_STRING_LENGTH);

    va_list pArgList;
    va_start(pArgList, szText);
    _vsnprintf(static_DebugerTmpBuffer,DEBUGER_MAX_STRING_LENGTH,szText, pArgList);
    va_end(pArgList);
    FILE *fp = fopen("c:\\debug.log","a");
    if(fp)
    {
    if(pszCategory)
    {
    if(pszCategory[0] != '\n')
    fprintf(fp,"\n");         
    fprintf(fp,pszCategory);
    fprintf(fp,":   ");
    } fprintf(fp,static_DebugerTmpBuffer);
    fclose(fp);
    }
    }