In C ++ programming, there are several predefined variables, which are convenient to use. For example, in C ++, in order to obtain the time, you often need to use the C language excuse time or ctime class, and then if it is a simple time acquisition, these predefined variables can be easily obtained. The following variables are reserved for C ++:
1) The _ line _ and _ file _ variables indicate the current row being processed and the current file. The _ file _ variable is useful for obtaining the path of the current program. You can simply use string STR (_ file _) to obtain the path of the current program.
2) The _ date _ variable indicates the current date, in the formatMonth/day/year(Month/day/year ).
3) The _ time _ variable describes the current time in the formatHour: minute: Second(Hour: minute: second ).
4) The _ cplusplus variable is defined only when a C ++ program is compiled.
The following code uses a program to view the content of these variables:
int main( int argc, char*argv[]){string str1(__FILE__);string str2(__TIME__);string str3(__DATE__);cout<<str1<<endl;cout<<str2<<endl;cout<<str3<<endl;return 0;}
The program execution result is as follows: