C++

Source: Internet
Author: User
Tags file handling


clock_t,size_t,time_t can represent system time and date as some sort of integer
Time Data int
The structure Type TM holds the date and time in C structure form;
C Structural Form Preservation
struct TM
{
int Tm_sec;//second seconds, normal range from 0~59, allowed to 61
int Tm_min;//minute min, range from 0~59
int tm_hour;//hours, RANGE 0~23
int tm_mday;//the day of the one month, the range 1~31
int Tm_mon;//month month, range from 0~11
int tm_year;//number of years since 1900
int tm_wday;//the day of the week, ranging from 0~6, starting from Sunday
int tm_yday;//The day of the year, ranging from 0~365, starting January 1
int tm_isdst;//Daylight Saving time Dayright save time (DST)
}

Date-time important functions, all of which are part of the C + + standard library

int tm_year;;/ /number of years since 1900
time_t time (time_t *time);
The function returns the current calendar time of the system, the number of seconds since 1970/01/01, the function returns the current calendar time of the system, the number of seconds elapsed since 1970/01/01, and returns 1 if the system does not have time.
Number of seconds per day
Seconds
1 minutes = 60 seconds
1 hours = 60 Minutes
1 days = 24 hours
Number of seconds per day = 24 * 60 * 60 = 86400
7 days a week = 7 * 86400 = 604800
One months 30 days count 30 * 86400 = 2592000
12 Months a year * 2592000 number of seconds to get one year = 31104000

About a year there are so many seconds, so since 1970/01/01 to present (2017/8) about 47 years the first number of seconds
Month 47 * 12 = 564;
564 * 2592000 = 1461888000
47 * 31104000 =


Char *ctime (const time_t *time);
Returns a string representing the local time, string
Char *ctime (const time_t *time);
Returns a string pointer representing local time char *ctime (const time_t *time) that returns a pointer to a local time string,
String Form Day month Hours:minutes:seconds year\n\0 wrap string end flag;

Char *ctime (const time_t *time);
Day month Hours:minutes:seconds Year\n\0;

struct TM *localtime (const time_t *time);
The function returns a pointer to the TM structure representing the local time;

struct TM *localtime (const time_t *time);
TM Structure Pointer
clock_t clock (void);
Four time-related types clock_t time_t size_t TM type clock_t size_t time_t can represent system time dates as some sort of integer
clock_t Clock
clock_t clock (void)
function returns the time that the processor clock takes to execute (the beginning of a program)
TM struct Point;
clock_t clock (void)
Returns a string pointer representing the local time
Returns a pointer to a string containing information stored in the structure that is pointed to by time, returning the form
Char *asctime (const struct TM *time);
Char *asctime (const struct)
struct TM *time

Char *asctime (const struct tm* time);
The function returns a pointer to a string containing the information stored in the structure that time points to
Day month date hours minutes seconds year

struct TM *gmtime (CONST TM * time);

struct TM *gmtime (const time_t *time);

function returns a pointer to time time for the TM structure

Universal Universal Time coordinated
Universal Time coordinated
Greenwich Mean Time;

time_t mktime (struct TM *time);
time_t mktime (struct TM *time);
function returns the calendar
size_t strftime ()
The function is used to format the date and time for the specified format;

Double Difftime (time_t time2,time_t time1);
function returns the number of seconds between time1 and Time2
Double Difftime (time_t time2,time_t time1);

Format time with Structured TM

struct TM
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int Tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
}

Tm
int tm_sec; 0 59 61
int tm_min; range from 0 59second minutes
24 0 23
Mday the first day of the one months
range from 1 ~ 31;
The day ordinal of an int one month

Month 0 ~ 11;
int tm_year;//year since 1900
int Tm_wday Day of the week, range 0 ~ 6;
int Tm_year The day ordinal of a year

int tm_dst;
C + + basic input and output
The standard library provides a rich set of input and output
The most basic and common IO in stdio programming
I/O occurs in a stream and the stream is a sequence of bytes
Stream bytes sequence;
Byte sequence io occurs in a stream that is a sequence of bytes
If
If the byte stream is flowing from the device to the memory keyboard disk network connection
The byte stream flows from the device keyboard to the disk drive network connection to the memory;
Output operation
s input output is the flow of bytes between the memory and the device
The byte stream flows from memory to device (display, printer, disk drive, network connection);

I/O waistband files

<iostream> cin cout cerr Clog object corresponding to standard input stream standard output stream non-buffered standard error stream buffer standard error stream
CIN cout Cerr Clog cin >> cout <<
Non-buffered standard error stream Cerr
Clog
Buffer standard error stream
iostream
CIN cout Cerr Clog;
Corresponding
Cerr Non-buffered standard error stream
Clog buffer standard error stream;
iostream

Iomanip
The document declares useful services for performing standardized IO through so-called parameterized stream operators (SETW and Setprecision)

Files through the so-called parameterized flow manipulators
The Iomanip file declares useful services for standardized IO through the so-called parameterized stream manipulator (SETW setprecision)
Iomanip
FStream files for user-controlled file handling declaration services we will discuss the details in the relevant chapters of the document and stream;
File handling declaration service for user-controlled files
The relevant chapters of the document and stream discuss the details;
FStream
Through the so-called parameterized flow manipulator SETW setprecision;
byte stream from device keyboard disk drive network connection flow to memory
The << operator is overloaded to output built-in types
Integer floating-point double string pointer
Stream extraction Operators
Stream insert
Standard input pre-defined object CIN is an instance of the IStream class Cin object attached to the standard input device is usually the keyboard cin is
Use with stream extraction operators >> collections

Standard output stream cout pre-defined objects
Standard output stream cout
Predefined object cout is an instance of the Ostream class cout objects connected to a standard output device
Cout object connected to standard output device, object connected to standard output device display

Output cout cout objects connected to standard output devices-display
cout with the stream insertion operator << with
<< Stream Insert operator cout object connection standard output device display

Object attached to the standard input device keyboard cin is a stream extraction operator >> set used

cout objects connected to standard output devices-display
CIN object negative to standard input device-keyboard cin is stream extraction operator >> associative
Cerr object attached to standard error device-standard error device-Display Cerr object is unbuffered every stream inserted into Cerr will be output immediately;
Cerr with the stream insertion operator << with

cout << Stream Insertion operator
cout >> stream extraction operators;
The Cin object is attached to the standard input device and usually the keyboard cin >> is used in conjunction with the stream extraction operator >>;
An instance of a predefined object ostream class; Clog object attached to standard error device clog object is buffered
means that each stream inserted into the clog is first stored in a buffered
Each stream inserted into the clog is first stored in the buffer until the buffer fills up or the buffer flush area is not output;

The Cerr stream displays an error message, and the other log messages are output using the clog stream;
Datastruct arrays allow you to define variables that store data items of the same type
Variables that can store data items of the same type
Data structure is a user-defined available datatype that allows different types of data items to be stored
structure is used to represent a record, and it may be necessary to track the following properties of each book, given the dynamics of the books in the library.
Title
Author
Subject
Book ID

A struct statement defines a new data type that contains multiple members
struct TYPE_NAME
{
Member_type1 member_name1;
Member_type2 member_name2;
Member_type3 Member_name3;
} object_names;

struct Books
{
Char title[50];
Char author[50];
Char subject[100];
int book_id;
} book;
The member access operator is a period between the struct variable name and the struct member we want to access
typedef long int *pint32;
Pint32 x, y, Z;
typedef struct
{
Char title[50];
Char author[50];
Char subject[100];
int book_id;
} Books; Books is the alias of the custom data, that is, the data type alias is the data type is not the data type variable;

When a function returns a reference, it returns a pointer to the return value of the hidden
The actual data type of the value of all pointers,
The actual data type of the pointer value is the same, which is a long hexadecimal number representing the memory address
The only difference between pointers to different data types is the data type of the variable or constant that the pointer points to
When using pointers in C + +, define a pointer variable, assign the variable address to the pointer, and access the value of the available address in the pointer variable;
Returns the value of the variable at the address specified by the operand
Defines a pointer variable, assigns the variable address to the pointer, accesses the pointer variable to store the value of the available address;
Returns the value of the variable at the address specified by the operand by using the unary operator * *;

The pointer contains the variable address, a pointer to the pointer, the first contains the address of the second pointer, and the second pointer to the position containing the actual value;
A pointer to a pointer of type int;
int **var;

C++

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.