法一:
在OnInitDialog中加入以下代码:
AllocConsole();
freopen("CONOUT$","w+t",stdout);freopen("CONIN$","r+t",stdin);
//cout << "Input:" <<endl;
printf("str = %s\n", "debug");
printf("sfffff= %c%s",'d',"cesshi");
//getchar();
//system("pause") ;//防止控制台一闪而过的两种方法
//fclose(stdout);
//fclose(stdin);
//FreeConsole();
法二:
#include <io.h>
#include <fcntl.h>
#include <stdio.h>
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);
}
InitConsoleWindow();
printf("str = %s\n", "debug");