stream I/O concept of a stream (slide G-5) sequence of characters streams are objects iostream classes istream ostream fstream classes (iostreams specialized for files) ifstream (input file stream) ofstream (output file stream) special predefined istream/ostream instances cin for standard input (keyboard) cout for standard output (screen) cerr for standard error (also screen, but usu. for error msgs.) member functions e.g. istream::getline(...), ostream::put(...) operators* insertion, << e.g. cout << "stuff to display on screen"; extraction, << e.g. cin >> userInputValue1 >> userInputValue2; *Which is which? Think from the program's point of view; "become the program." If you want to send text to the screen, you do so by sending it through the cout stream object, so you must "insert" the text into cout. istream extraction, breaking at whitespace (slide G-10) see also, method istream::getline(char [], int) checking for a valid istream general method: just use stream object itself, e.g. while (cin) { cin >> anotherValue; // do something w/ the inputted value } more specific: check for failure of a particular extraction while (cin >> anotherValue) { // do something w/ the inputted value } In the example above, if the user input does not match the type of variable anotherValue, the loop condition (cin expression) evaluates to false. file streams opening a file for reading by creating an instance of ifstream associated w/ the file: ifstream inputStream("inputFilename", ios::nocreate); Now, extracting from object inputStream reads from the file sequentially: inputStream >> firstValue >> secondValue; opening a file for writing by creating an instance of ofstream associated w/ the file: ofstream outputStream("outputFilename"); Now, inserting to object outputStream writes to the file sequentially: outputStream << "This string is 29 bytes long.";