Introduction to several predefined variables in C ++

Source: Internet
Author: User

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:




Related Article

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.