Function declaration:
1. Implicit Declaration: If no declaration is made, the system can call the function based on the parameter type (errors may occur)
2. Explicit declaration: declaration before being called, for example, double add (double, double); function declaration parameters can only write types, and do not need to write function bodies.
File Operations:
Fopen -- open the file, file * pfile = fopen ("a.txt", "W ");
Fopen open mode:
R: only readable. The file must exist.
R +: readable and writable. The file must exist.
W: Write only. Create a file. If the file exists, delete the old file first.
W +: readable and writable. Create a file. If the file exists, delete the old file first.
A: It can only be written. If it does not exist, a file is created. If it exists, the file content is not modified and the content is appended.
A +: readable and writable. If the object does not exist, the file is created. If the object exists, the file content is not modified and the content is appended.
B: The file is operated in binary format and can be used in combination with the preceding two types.
Fwrite -- write content to the file, int arr [5] = {0}; fwrite (ARR, sizeof (INT), 5, pfile );
Fread -- read content from the file, int arr [5] = {0}; fread (ARR, sizeof (INT), 5, pfile );
Fclose -- close the file, fclose (pfile); pfile = NULL;
Fputs -- write content, char STR [20] = {'A', 'B'}; fputs (STR, pfile );
Fgets -- read content, char STR [20] = {0}; fgets (STR, 20, pfile); // read 19 characters from the file + '\ 0'
Ftell (File * pfile) -- get the distance from the start of the pointer. If the current pointer is the end of the file, you can get the file size.
Rewind (File * pfile) -- move the pointer position to the beginning
Fseek (File * pfile, int relativeposition, seek_flag flag) -- locate the read/write pointer
Flag:
Start with seek_set --
Seek_cur -- current location
Seek_end -- end of a file
Union: multiple variables share a piece of memory. At the same time, only one member variable has a valid value.
For example:
Union {
Int I;
Double D;
} Myunion;
Enumeration type:
Enum color {red, blue, green}; // The values converted to int are 0, 1, and 2 in sequence.
Enum color {Red = 1, Blue = 4, green}; // convert to int values in sequence:, 5
Usage:
Enum color {Red = 5, blue, green} mycolor, mycolor1; // defines two variables.
Mycolor = (Enum color) 7;
Cout <(INT) Blue <Endl; // directly use