怎样使程序打印出错误的行号
如题,用ANSI的标准预定义宏使程序打印出错误的行号。
求高手解答~
[解决办法]
请楼主google“__LINE__ 宏”
另外,楼主结贴率好像偏低,得到满意答案后,请注意结帖,这样才会有更多的热心人帮你
[解决办法]
__FILE__ 是显示那个文件。
__LINE__ 是显示文件里面的哪一行。
__FUNCTION__ 是显示在哪个hanshu
[解决办法]
ISO/ANSI C++03:
16.8 Predefined macro names [cpp.predefined]
1 The following macro names shall be defined by the implementation:
__LINE__ The line number of the current source line (a decimal constant).
__FILE__ The presumed name of the source file (a character string literal).
__DATE__ The date of translation of the source file (a character string literal of the form
"Mmm dd yyyy", where the names of the months are the same as those generated by the asctime
function, and the first character of dd is a space character if the value is less than 10). If the date of
translation is not available, an implementation-defined valid date is supplied.
__TIME__ The time of translation of the source file (a character string literal of the form "hh:mm:ss"
as in the time generated by the asctime function). If the time of translation is not available, an
implementation-defined valid time is supplied.
__STDC__ Whether__STDC__ is predefined and if so, what its value is, are implementation-defined.
__cplusplus The name __cplusplus is defined to the value 199711L when compiling a C++
translation unit.143)
注意__FUNCTION__不是标准预定义宏。
具体例子:
#include<cstdio>
using namespace std;
void debug_print(const char* info, const char* file, int line)
{
printf("error: %s, line %i at %s;", info, line, file);
}
#define DEBUG_PRINT(error) debug_print(#error, message, __LINE__, __FILE__)
int main()
{
DEBUG_PRINT(test);
getchar();
return 0;
}
[解决办法]
err...上面参数列表里面file和line写反了...