C++/C Get CPP file line number with file name

Source: Internet
Author: User
Tags sprintf

Compiler built-in macros:

We first introduce several compiler built-in macro definitions, these macro definitions can not only help us to complete the cross-platform source code writing, flexible use can also skillfully help 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.

The following example:

[CPP]View Plaincopy
  1. #include <stdio.h>
  2. int main ()
  3. {
  4. Char file[16];
  5. Char func[16];
  6. int line;
  7. sprintf (file,__file__); //File name
  8. sprintf (func,__function__); //Function name
  9. printf ("file=%s\n", file);
  10. printf ("func=%s\n", func);
  11. printf ("%05d\n", __line__); Line number
  12. return 0;
  13. }

C++/C Get CPP file line number with file name

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.