I have been using Petru's logging framework a bit. This is part of his code:
class Output2FILE
{
public:
static FILE*& Stream() {
static FILE* pStream = stderr;
return pStream;
}
};
Which is very nice as it simply logs to stderr without any action, but with the function that can afterwards be set to anything including stdout and a file. However, I think this approach can't be used for formatted data as one needs to use fprintf.
Hence I am trying to come up with something similar that lets one use stdout by default and that can be switched to a file, but using the "<<" operator for formatted data.
Maybe something along the lines of
std::ostream myOutput(std::cout);
with the idea of then doing myOutput << "Hello" << 1 << 1.5;
. Above line however makes the compiler complain though.
What is the correct way?
Thanks!