zoukankan      html  css  js  c++  java
  • linux下可变参数打印

    参考c++文档的可变参数打印进行修改

    #include <stdio.h>
    #include <stdarg.h>
    #include <time.h>
    
    FILE * pFile = NULL;
    
    void WriteFormatted (const char* pfileName , const char* pfun , const long lline, const char * format, ...)
    {
            if(!pFile) return;
    
            time_t timep;
            time (&timep);
            char tmp[64];
            strftime(tmp, sizeof(tmp),/* "%Y-%m-%d %H:%M:%S"*/"%F %T",localtime(&timep) );
    
            fprintf(pFile,"%s %s:%s:%ld  ",tmp,pfileName,pfun,lline);
    
            va_list args;
            va_start (args, format);
            vfprintf (pFile, format, args);
            va_end (args);
    
    }
    
    
    #define debuglog(format, ...)    WriteFormatted(__FILE__, __FUNCTION__, __LINE__, format, ##__VA_ARGS__)
    
    int main ()
    {
            pFile = fopen ("myfile.txt","a+");
    
            debuglog("Call with %d variable %s.
    ",2,"arguments");
            debuglog("Call with %d variable %s.
    ",2,"arguments");
            debuglog("Call with %d variable %s.
    ",2,"arguments");
            debuglog("Call with %d variable %s.
    ",2,"arguments");
            debuglog("Call with %d variable %s.
    ",2,"arguments");
            debuglog("Call with %d variable %s.
    ",2,"arguments");
    
            fclose (pFile);
            return 0;
    }
  • 相关阅读:
    拦截器
    Ajax
    JSON
    数据处理及跳转
    RestFul和控制器
    第一个MVC程序
    什么是SpringMVC
    回顾MVC
    声明式事务
    微软最强 Python 自动化工具开源了!不用写一行代码!
  • 原文地址:https://www.cnblogs.com/nanqiang/p/13071420.html
Copyright © 2011-2022 走看看