#include <iostream>
#include <stdio.h>
#include <stdarg.h>
#define dbgPrintf(format, ...) printf(format, __VA_ARGS__)
using namespace std;
class Log
{
public:
Log (){
}
void println(const char* format, ...){
va_list argptr; // 实际上是一个 const char * 类型
va_start( argptr, format );
//dbgPrintf(format, argptr) ;
vprintf(format, argptr) ;
printf("\n") ;
va_end(argptr) ; // 等价于 argptr = NULL ;
}
private:
/* data */
};
int main()
{
Log mlog ;
int a = 90 ;
mlog.println("hello %d %d", a, a) ;
printf("hello %d %d\n", a, a) ;
return 0;
}
编译运行:
$ g++ log.cpp
$ ./a.out