首页 > 其他 > 详细

重定向标准输出到控制台

时间:2015-04-23 01:56:10      阅读:158      评论:0      收藏:0      [点我收藏+]
#ifdef DISPLAYCONSOLE
    // Redirection of standard output to console
    int hCrt;  BOOL rep;  FILE *hf;
    _SYSTEM_INFO lps;
    GetSystemInfo(&lps);
    rep = AllocConsole();
    hCrt = _open_osfhandle((long) GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT);
    hf = _fdopen( hCrt, "w" );
    *stdout = *hf;
    // stop the buffer on stdout
    //  int i = setvbuf( stdout, NULL, _IONBF, 0 );
    //  filebuf ff(hCrt);
    //  cout = &ff;
    printf("This Debug Window  will disappear in release mode\n");
    #endif //  DISPLAYCONSOLE

还需要在代码中声明

#define DISPLAYCONSOLE

 

重定向标准输出到控制台

原文:http://www.cnblogs.com/mumuli/p/4449156.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!