How can I derive a class from cout
so that, for example, writing to it
new_cout << \"message\";
would be equivalent to
class Log
{
public:
Log(const std::string &funcName)
{
std::cout << funcName << ": ";
}
template
Log &operator<<(const T &v)
{
std::cout << v;
return *this;
}
~Log()
{
std::cout << " [end of message]" << std::endl;
}
};
#define MAGIC_LOG Log(__FUNCTION__)
Hence:
MAGIC_LOG << "here's a message";
MAGIC_LOG << "here's one with a number: " << 5;