How would you "close" a stream that might be instantiated as a stream that cannot be closed?
Specifically, there are programs that default to stdout if you don't specify an output file but can have other forms of output. The code would probably be something like:
Then before the program terminates, you'd (want to) haveCode:ostream* os; if (argc[X] != '-') os = &cout; else os = new ofstream("out");
Which obviously will throw an error since ostream doesn't have a "close" method. One work around could beCode:os->close();
But what I would like to know is whether there is a way of instantiating a "stream" in a way as to make it possible to "close" it in runtime with only methods internal to the stream class.Code:if(some boolean flag indicating that you have a file stream has been set) os->close();