环境为Window10+VS2017+Opencv3.2
日志文件函数的写法
void Log(std::string theWriteData,bool ifNewLine)
{
std:: string theData;
time_t rawtime;
struct tm* timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
FILE *fp;
fp = fopen("C:\\Users\\user\\Desktop\\simon涂胶项目\\涂胶Opencv\\x64\\Debug\\log\\log.txt", "a+");
if (fp == NULL)
{
std::cout << "write Log error" << std::endl;
std::exit(1);
}
theData = std::to_string(((timeinfo->tm_year) + 1900)) + ":" + std::to_string(timeinfo->tm_mon + 1) + ":" + std::to_string(timeinfo->tm_mday) + ": " + std::to_string(timeinfo->tm_hour) + ":";
theData = theData + std::to_string(timeinfo->tm_min) + ":" + std::to_string(timeinfo->tm_sec);
// theData = theData +" "+ theWriteData;
if (ifNewLine)
{
if (theWriteData != "")
{
theData = theData +"***************" + theWriteData;
fprintf(fp, "%s\n", theData.c_str());
}
else
{
fprintf(fp, "\n");
}
}
else
{
fprintf(fp, "%s", (theWriteData + " ").c_str());
}
fclose(fp);
}
结果如此显示