For the file operation, I was mainly in contact with Linux under the set, and to C + + learning a bit, but also found some similarities and differences
First file class requires header files # include <stdio.h>
For open file operations, the fopen function is used under Linux, and a warning is reported when VS2010 uses this function
Error C4996: ' fopen ': This function or variable could be unsafe. Consider using fopen_s instead. To disable deprecation, use _crt_secure_no_warnings. See online Help for details.
1> C:\Program Files (x86) \microsoft Visual Studio 12.0\vc\include\stdio.h (211)
VS, I suggest you use fopen_s.
erron_t ret = fopen_s (&file*, "FILENAME", "open Mode");
Open successfully returns 0, the failure returns a value other than 0.
It is worth mentioning that:
File directories in VS need to use \ \ This is not the same as the \ in Linux to distinguish the file level
There's a little bit easier to forget. That is, when the file is opened, the location of the file pointer is related to the open mode, the specific relationship is as follows:
/***************************/
File open with file pointer location
R (read file) file header
W (write file) file header
A (a +) append content file Footer
/***************************/
Files opened with "W" can only be written to the file. If the open file does not exist, the file is created with the specified file name, and if the open file already exists, the file is deleted and a
For file length, the file pointer can be offset to the file header via the rewind () function, and then through Fseek (file*, 0L, seek_end);
How to read and write files
There are fread fwrite fputs fgets and other functions, through these and feof collocation we can realize the detailed operation of reading and writing, see function prototype.
Remember to close the file handle after we're done fclose (file*);
Summary of C + + File class Learning