The pre-processor defines four useful constants for us. Using these four constants, we can provide more information in the error message. They are:
_ FILE name
_ LINE _ current row number
_ TIME _ file Compilation TIME
_ DATE on which the file is compiled
For example, we can use the following small example to check the usage of these constants. The function is to determine whether the input word is smaller than the minimum defined length. If it is smaller than the input word, an error message is output. The Code is as follows:
[Cpp]
# Include <iostream>
# Include <string>
Using namespace std;
Int main ()
{
Const string: size_type THRESHOLD = 3;
String word;
Cin> word;
If (word. size () <THRESHOLD ){
Cerr <"Error:" <_ FILE _ <endl <"\ tline" <_ LINE _ <endl
<"\ TComplied on" <_ DATE _ <"at" <_ TIME _ <endl
<"\ TWord read was" <word <": Length too short" <endl;
}
Return 0;
}
Input the string "AB" and the output is as follows:
By RO_wsy