MFC program Display console output

Source: Internet
Author: User

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

    1. void initconsolewindow()
    2. {
    3. int ncrt = 0;
    4. file* FP;
    5. AllocConsole ();
    6. NCRT = _open_osfhandle ((long) GetStdHandle (Std_output_handle), _o_text);
    7. fp = _fdopen (NCRT, "w");
    8. *stdout = *FP;
    9. Setvbuf (stdout, NULL, _IONBF, 0);
    10. }



2, add the following code where the program starts, and the MFC program is added to the InitInstance function

      1. FILE *stream;
      2. AllocConsole ();
      3. Setconsoletitle (_t ("Debug Console"));
      4. Freopen_s (&stream,"conout$", "W", stdout);

MFC program Display console output

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.