Original article: http://blog.csdn.net/brucezong/article/details/6889974
When debugging the MFC program, we often need to view the output values of variables at specific locations. Or an output identifier is provided when a specific condition is executed.
Generally, there are three methods:
1) Call the trace (lpctstr lpszformat,...) Function
It is very convenient to use the trace function in MFC to print the output results, which is similar to the use of the printf function in the console program. But there are several points
Note: 1. The output of the trace function is under the debug option of the output window. 2. The output is only available when debugging the debug version.
The output is not displayed when the release version is used to debug or run the program.
2) use the afxmessagebox () function to output information.
This function is also commonly used for debugging. It is easy to use and is not described here.
3) direct the standard output to the console you have created
# Include "Io. H"
# Include "fcntl. H"
Void initconsole ()
{
Int nret = 0;
File * FP;
Allocconsole ();
Nret = _ open_osfhandle (long) getstdhandle (std_output_handle), _ o_text );
Fp = _ fdopen (nret, "W ");
* Stdout = * FP;
Setvbuf (stdout, null, _ ionbf, 0 );
}
Call this function at the place where the MFC program is initialized. You can use the console to view the printing information of the printf function.
When debugging the MFC program, we often need to view the output values of variables at specific locations. Or an output identifier is provided when a specific condition is executed.
Generally, there are three methods:
1) Call the trace (lpctstr lpszformat,...) Function
It is very convenient to use the trace function in MFC to print the output results, which is similar to the use of the printf function in the console program. But there are several points
Note: 1. The output of the trace function is under the debug option of the output window. 2. The output is only available when debugging the debug version.
The output is not displayed when the release version is used to debug or run the program.
2) use the afxmessagebox () function to output information.
This function is also commonly used for debugging. It is easy to use and is not described here.
3) direct the standard output to the console you have created
# Include "Io. H"
# Include "fcntl. H"
Void initconsole ()
{
Int nret = 0;
File * FP;
Allocconsole ();
Nret = _ open_osfhandle (long) getstdhandle (std_output_handle), _ o_text );
Fp = _ fdopen (nret, "W ");
* Stdout = * FP;
Setvbuf (stdout, null, _ ionbf, 0 );
}
Call this function at the place where the MFC program is initialized. You can use the console to view the printing information of the printf function.