istream *input = &cin; fstream file; // ... file.open( ... ) //... if( file.is_open() ) input = &file;