Is there a common interface for cin and file input?
I want to make a program that has an optional parameter
prog [input-file]
If an input file is specified, then it should read from the file, and if not, it should read from cin.
From what I can tell, they both implement istream. How would you set up it so that I could do something like in >> var, where in is an istream.
You could shift some of this work into a helper class to make it clearer what’s going on (note that this has slightly different behavior in the case where the file can’t be opened):