首页 > 代码库 > C++ streambuf用法
C++ streambuf用法
class LogStreamBuf : public std::streambuf { public: // REQUIREMENTS: "len" must be >= 2 to account for the ‘\n‘ and ‘\n‘. LogStreamBuf(char *buf, int len) { setp(buf, buf + len - 2); } // This effectively ignores overflow. virtual int_type overflow(int_type ch) { return ch; } // Legacy public ostrstream method. size_t pcount() const { return pptr() - pbase(); } char* pbase() const { return std::streambuf::pbase(); }};
class LogStream : public std::ostream { public: LogStream(char *buf, int len, int ctr) : std::ostream(NULL), streambuf_(buf, len), ctr_(ctr), self_(this) { rdbuf(&streambuf_);} int ctr() const { return ctr_; } void set_ctr(int ctr) { ctr_ = ctr; } LogStream* self() const { return self_; } // Legacy std::streambuf methods. size_t pcount() const { return streambuf_.pcount(); } char* pbase() const { return streambuf_.pbase(); } char* str() const { return pbase(); } private: base_logging::LogStreamBuf streambuf_; int ctr_; // Counter hack (for the LOG_EVERY_X() macro) LogStream *self_; // Consistency check hack };
C++ streambuf用法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。