Linux下C++简单的写日志

#include <time.h>
#include <stdio.h>

void DataBase::WriteInfo(int num)
{
	time_t timer;
	char bufferTime[20];
	time(&timer);
	strftime(bufferTime,20,"%Y-%m-%d %H:%M:%S",localtime(&timer));
	//FILE* fid=fopen("/opt/HaiBao/Info.log","a+");
	FILE* fid=fopen("myInfo.log","a+");//a+:没找到myInfo.log文件,则创建。myInfo.log是与可执行文件(Debug,ARM,Relese)在同一目录
	if(fid==NULL)
	{
		printf("the myInfo.log is not exist!!!\n");
		return;
	}
	fprintf(fid,"%s",bufferTime);
	fprintf(fid," algorithmVersion:%d",num);
	fprintf(fid,"\n");
	fclose(fid);
}

你可能感兴趣的:(linux)