Several pre-defined macros for C + +: __date__,__time__,__file__,__line__

Source: Internet
Author: User

On the other hand, the C + + compiler will have several macros built into it, which not only helps us to complete the cross-platform source code, but also subtly helps us to output very useful debugging information.

There are several standard scheduled macros (also commonly used) in the ANSI C standard:

    • __LINE__: Inserts the current source code line number in the source code;
    • __FILE__: Inserts the current source filename in the source file;
    • __DATE__: Insert the current compilation date in the source file
    • __TIME__: Inserts the current compile time in the source file;
    • __STDC__: The identifier is assigned a value of 1 when the program strictly complies with the ANSI C standard;
    • __cplusplus: This identifier is defined when you write a C + + program.
#include <stdio.h>intMainvoid) {    intanswer; //__date__, __time__, __file__, __line__ for pre-defined macrosprintf"Date:%s\n", __date__); printf ("Time :%s\n", __time__); printf ("File:%s\n", __file__); printf ("Line :%d\n", __line__); printf ("Enter 1 or 0:"); scanf ("%d", &answer); //This is a conditional expressionprintf"%s\n", answer?"You said YES":"You said NO");}



Several pre-defined macros for C + +: __date__,__time__,__file__,__line__

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.