I would like to do something like this:
std::wistream input = std::wifstream(text);
if (!input) input = std::wistringstream(text);
// read from input
i.e. have text either interpreted as a filename, or, if no such file exists, use its contents instead of the file's contents.
I could of course use std::wistream * input
and then new
and delete
for the actual streams. But then, I would have to encapsulate all of this in a class (constructor and destructor, i.e. proper RAII for exception safety).
Is there another way of doing this on the stack?