Use the console to debug programs in non-console programs.

Source: Internet
Author: User

In some cases, you must use the console to print logs for debugging programs that are not in the console program. You can use the following class. Rough writing,

Class cconsolelog
{
Public:
Cconsolelog (void );
~ Cconsolelog (void );
Void log (char * format ,...);
};

# Include <windows. h>
# Include <stdio. h>
# Include <stdarg. h>

 

Cconsolelog: cconsolelog (void)
{
Bool ret = allocconsole ();
If (! RET)
{
Throw "allocconsole failed ";
}
Freopen ("con", "W", stdout );
}

Cconsolelog ::~ Cconsolelog (void)
{
Bool ret = freeconsole ();
If (! RET)
{
Throw "Free Console Failed ";
}
}

Void cconsolelog: log (char * format ,...)
{
Va_list AP;
Char Buf [255] = {0 };
Va_start (AP, format );
Vsprintf (BUF, format, AP );
Va_end (AP );
Fprintf (stdout, Buf );
Return;
}

Write down to facilitate future search

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.