I. IO class
1. iostream defines the basic type of read-write stream, FStream defines the type of read-write named file, Sstream defines the type of read-write memory string object
2. The IO object cannot be copied, so the formal parameter or return type cannot be set to the stream type: usually by reference and by side reflow
3. Reading and writing an IO object will change its state, so the passed and returned references cannot be const.
4. You should always check if it is in good condition before using a stream
5, Management output buffer
- By default, CIN and Cerr are associated to cout, so reading CIN or writing cerr will cause the cout buffer to be flushed
" hi! " << end; // output Hi and a newline character, then flush the buffer " hi! " << flush; // output Hi, flush buffer, no extra characters attached " hi! " << ends; // output hi and a null character, flush buffer
Ii. file input and output
1. Ifstream reads data from a given file, Ofstream writes data to a given file, FStream can read and write to a given file
2. Open File: FStream fstrm (s, mode); Open file by mode mode
inch // Open in read mode out // Open The app by writing // Locate to the end of file after each write operation / // Open file immediately to end of file trunc // truncate file binary // Binary mode for IO
By default, files opened in out mode are truncated even if trunc is not specified
To best Moss must specify the app mode himself to append write (Ofstream::out | Ofstream::app)
Eighth Chapter: IO Library