可以为应用程序创建一个关联的DOS窗口,然后把输出重定向到窗口,查看输出log
AllocConsole();
freopen("CONOUT$", "w", stdout);
根据时间将log输出到日志文件
time_t timep;
time(&timep);
struct tm *p = localtime(&timep);
char szBuff[64] = {0};
sprintf(szBuff, "%d-%d-%d %d:%d:%d.log", (1900 + p->tm_year), (1 + p->tm_mon), p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
std::string str = szBuff;
std::size_t pos = str.find(":");
while (pos != std::string::npos)
{
str.replace(pos, 1, ":");
pos = str.find(":");
}
freopen(str.c_str(), "w", stdout);