如何输出源文件的标题和目前执行行的行数
2012-03-19 19:42
267 查看
/**************************** *功能:输出源文件的标题和当前执行 * 行的行数 *目的:知识学习 ****************************/ #include<iostream> using namespace std; void main() { int line=__LINE__;//注意:LINE前后分别是两个下划线“-”(半角状态下) char*file=__FILE__; cout<<"file name is "<<(file)<<",line is "<<line<<endl; }
Table 1.1 ANSI Predefined Macros
Macro | Description |
__DATE__ | The compilation date of the current source file. The date is a string literal of the formMmm dd yyyy. The month nameMmm is the same as for dates generated by the library functionasctime declared in TIME.H. |
__FILE__ | The name of the current source file. __FILE__ expands to a string surrounded by double quotation marks. |
__LINE__ | The line number in the current source file. The line number is a decimal integer constant. It can be altered with a#line directive. |
__STDC__ | Indicates full conformance with the ANSI C standard. Defined as the integer constant 1 only if the /Za compiler option is given and you are not compiling C++ code; otherwise is undefined. |
__TIME__ | The most recent compilation time of the current source file. The time is a string literal of the formhh:mm:ss. |
__TIMESTAMP__ | The date and time of the last modification of the current source file, expressed as a string literal in the formDdd Mmm Date hh:mm:ss yyyy, whereDdd is the abbreviated day of the week andDate is an integer from 1 to 31. |
命令# line改变_LINE_ 与_ F I L E _的内容,它们是在编译程序中预先定义的标识符。
命令的基本形式如下:
# line number["filename"]
其中的数字为任何正整数,可选的文件名为任意有效文件标识符。行号为源程序中当前行号,文件名为源文件的名字。命令# line主要用于调试及其它特殊应用。
函数“line”举例
例如,下面说明行计数从1 0 0开始;printf( ) 语句显示数1 0 2,因为它是语句#line 100后的第3行。
#line 100 /* 初始化行计数器* /
main ( ) /* 行号100 是从定以后的下一行开始计数的*/
{ /* 行号101 */
p r i n t f ( " % d \ n " ,_ line _ ) ; /* 行号102 */
}
相关文章推荐
- 如何输出源文件的标题和目前执行行的行数
- 如何输出源文件的标题和目前执行行的行数
- 如何输出源文件的标题和目前执行行的行数
- 如何输出源文件的标题和目前执行行的行数
- 如何输出源文件的标题和目前执行行的行数
- C语言输出源文件的标题和目前执行行的行数以及时间和日期
- 输出源文件的标题和目前执行行的行数
- 小知识(输出源文件的标题和目前执行行的行数)
- 输出源文件的标题,目前执行行的行数,编译时间
- 如何通过cl_dd_document来实现在ALV中输出标题头
- GCC从源文件如何蜕变成可执行文件
- 如何快速的知道程序中输入的大段数据哪一行没有被正确执行或输出
- 在android中如何编译连接 .c 的可执行文件 Android点滴(1) -- 执行Linux命令并且获得输出的结果
- 【C语言】【unix c】如何将多个源文件拼接成一个可执行文件?
- 如何把Java源文件转化为可执行文件
- 如何执行本地程序并捕获out和err输出(written in Java)
- PHP中如何实现 “在页面中一边执行一边输出” 的效果
- 如何截获执行命令行的输出
- (2012.01.03) 输出程序中的指定位置的行数与该文件的路径及标题。
- 1.4 如何在main()方法之前执行输出“hello world”