I/O Streams





Input File Basics

#include <fstream> ifstream ifile ; // input file ifile.open("fname") ; // open file, C-string name if (ifile.fail( ) ) { // bad file?? ... } ifile >> ... ifile.close() ;



getline()





Formatted Output

Formatting commands stay in effect until reset.





Other output stream functions





Manipulators





Eliminating Side-Effects

Function calls should not have any side-effects.

void nice_func() { // save settings // int savePrecision = outStream.precision( ); int saveFlags = outStream.flags( ); ... // restore settings // outStream.precision( savePrecision ); outStream.flags( saveFlags ): return ; }



String Streams





Inheritance