1.打印并带有时间
#include <iostream>
#include <unistd.h>
#include <sys/time.h>
#include <fstream>
#include <stdarg.h>
using namespace std;
#define printf log
void log(const char *format, ...)
{
ofstream outfile("./log.txt", ios::app);
time_t timep;
time (&timep);
char time_buf[64];
strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S",localtime(&timep) );
va_list args;
va_start(args, format);
char buf[4096] = {0};
vsprintf(buf, format, args);
va_end(args);
outfile << time_buf << " ";
outfile << buf << endl;
}
int main()
{
printf("hello:%s%d, %s%d", "practice", 1, "practice", 2);
return 0;
}