windows下log的重定向输出

来源:互联网 发布:各种编程语言的区别 编辑:程序博客网 时间:2024/06/04 18:42

可以为应用程序创建一个关联的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);

0 0
原创粉丝点击