#include <fstream>
#include <iostream>
#include <string>
struct Logger
{
Logger(std::ostream& os) : m_log(os.rdbuf()) { }
std::streambuf* reset(std::ostream& os)
{
return m_log.rdbuf(os.rdbuf());
}
template <typename T> friend Logger& operator<<(Logger& os, const T& t)
{ os.m_log << t; return os; }
friend Logger& operator<<(Logger& os, std::ostream& ( *pf )(std::ostream&))
{ os.m_log << pf; return os; }
private:
std::ostream m_log;
};
int main(int argc, const char *argv[])
{
Logger logto(std::cout);
logto << "Hello world" << std::endl;
logto.reset(std::cerr);
logto << "Error world" << std::endl;
return 0;
}
I2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4KCnN0cnVjdCBMb2dnZXIKewogICAgTG9nZ2VyKHN0ZDo6b3N0cmVhbSYgb3MpIDogbV9sb2cob3MucmRidWYoKSkgeyB9CgogICAgc3RkOjpzdHJlYW1idWYqIHJlc2V0KHN0ZDo6b3N0cmVhbSYgb3MpIAogICAgewogICAgICAgIHJldHVybiBtX2xvZy5yZGJ1Zihvcy5yZGJ1ZigpKTsKICAgIH0KCiAgICB0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4gZnJpZW5kIExvZ2dlciYgb3BlcmF0b3I8PChMb2dnZXImIG9zLCBjb25zdCBUJiB0KQogICAgeyBvcy5tX2xvZyA8PCB0OyByZXR1cm4gb3M7IH0KCiAgICBmcmllbmQgTG9nZ2VyJiBvcGVyYXRvcjw8KExvZ2dlciYgb3MsIHN0ZDo6b3N0cmVhbSYgKCAqcGYgKShzdGQ6Om9zdHJlYW0mKSkKICAgIHsgb3MubV9sb2cgPDwgcGY7IHJldHVybiBvczsgfQogICAgCiAgcHJpdmF0ZToKICAgIHN0ZDo6b3N0cmVhbSBtX2xvZzsKfTsKCmludCBtYWluKGludCBhcmdjLCBjb25zdCBjaGFyICphcmd2W10pCnsKICAgIExvZ2dlciBsb2d0byhzdGQ6OmNvdXQpOwoKICAgIGxvZ3RvIDw8ICJIZWxsbyB3b3JsZCIgPDwgc3RkOjplbmRsOwoKICAgIGxvZ3RvLnJlc2V0KHN0ZDo6Y2Vycik7CiAgICBsb2d0byA8PCAiRXJyb3Igd29ybGQiIDw8IHN0ZDo6ZW5kbDsKCiAgICByZXR1cm4gMDsKfQoKCg==