您的位置:首页 > 其它

windows下log的重定向输出

2016-07-18 10:34 127 查看
可以为应用程序创建一个关联的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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  日志 重定向