Console 多开

1、在项目自动生成的stdafx.h文件中添加下面头文件
#include <io.h>
#include <fcntl.h>
#include <stdio.h>
 
2、把下面的函数加到你初始化的地方,然后你就可以使用printf函数了
void InitConsoleWindow()
{
    int nCrt = 0;
    FILE* fp;
    AllocConsole();
    nCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
    fp = _fdopen(nCrt, "w");
    *stdout = *fp;
    setvbuf(stdout, NULL, _IONBF, 0);
}
以下红色部分是我初始化函数中添加的
BOOL CSerialPortptestDlg::OnInitDialog()
{ ...

  ...

  ...

  ...
 InitConsoleWindow();
 printf( "str   =   %s\n ",   "debug"); 
调用此函数后会弹出一个CONSOLE,然后printf的东西就会出现在上面。

猜你喜欢

转载自blog.csdn.net/linuxheik/article/details/83418351