Using the C-style file manipulation function, you need to include the stdio.h header file.
1. function to open the file:
1 // The value of Oflag is "W" or "R", which means to open it in either write or read 2 file* fd = fopen (Filename.c_str (), oflag);
2. Function prototypes for writing files:
size_t fwrite (constvoid* buffer, size_t size, size_t count, file* Stream);
Where buffer is the first address pointer that needs to be written to the file in memory, size is the number of bytes per element to write to, count is how many elements to write, stream is the file pointer, and the example is as follows:
1 FILE * FP; 2 fp = fopen ( filename , " WB " ) int a[3 ] = {1 , 2 , 3 }; 4 fwrite (A, sizeof (int ), 3 , FP); 5 fclose (FP);
3. The prototype of a read file function is very similar to writing a file:
size_t fread (constvoid* buffer, size_t size, size_t count, file* Stream);
4. Functions to obtain file information:
1 struct stat statbuf; 2 Fstat (Fileno (FP), &statbuf);
The resulting statbuf is the structure that contains the file information, such as Statbuf.st_size is the size of the Get file
5. Move the file location pointer function prototype:
int fseek (FILE *fp,long offset,int origin);
The first parameter is the file pointer, the second argument moves the offset, and the third parameter moves from there, with 3 macro seek_set (0) representing the beginning of the document, Seek_cur (1) representing the file's current position, and seek_end (2) indicating the end of the file (not recommended for numbers, Preferably with a macro)
6. Do not forget to close the file oh:
Fclose (FP);
C language-style file manipulation functions