1. Open and close the file:
file* fp = fopen (String.c_str (), FLAG);
- STRING.C_STR (): Requires C-language string form;
- Flag Description:
- R: Read-only mode open;
- W: Write-only mode open;
- A: Open by append mode;
- r+: Open in read/write mode; (No files: error)
- w+: Open in read/write mode; (no files: new)
int fclose (file* fp);
- Success: returns 0;
- Failure: Returns EOF;
2. Read and Write files:
- N-1 characters are read from the stream, unless a line is read, the parameter S is to receive the string, and if successful returns a pointer to s, otherwise null
3. End of file test: int feof (*FP);
The end of the currently reached file returns non 0, otherwise returns 0
Using the FStream method:
1. Include Header files:
#include <fstream>ofstream //File write operation memory writes to storage device Ifstream //file read operation, storage device read to memory FStream
2. Open the file:
void Open (const char * filename, Ios_base::openmode mode = Ios_base::in | ios_base::out); void open (const wchar_t *_file Name, Ios_base::openmode mode= ios_base::in | ios_base::out, int prot = Ios_base::_openprot);
Read and write files for [C + + language Basics]