An overview of c++ file streams, focusing on the use of ifstream, ofstream, and fstream for input, output, and bidirectional file operations. Topics include class hierarchies, file processing modes, file protection modes, and examples of open() and close() functions.
The stream’s error flag is cleared unless the close fails.
Syntax
void close()
Usage
my_file.close();
File I/O – Example contd…
//Until the end of file is reached, read from //the file and write it to the out file and echo on the screen. while(fIn.get(cCh)) { fOut.put(cCh); cout.put(cCh); //echo on terminal ++nCnt; }
//Write the final byte count cout << "[ " << nCnt << " ]" << endl; fOut << nCnt;