Sometimes, we write something in C, we may need to test MFC as a UI input parameter, but there are a lot of printf operations in the program, which requires the MFC program to open at the same time
One console for standard output
Query the network, the approximate method has the following two kinds
1, add a global function, the content is as follows, and then when the program starts to call
- 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);
- }
2, add the following code where the program starts, and the MFC program is added to the InitInstance function
- FILE *stream;
- AllocConsole ();
- Setconsoletitle (_t ("Debug Console"));
- Freopen_s (&stream,"conout$", "W", stdout);
MFC program Display console output