C++ streambuf用法
2024-08-25 09:42:17
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 - );
}
// 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++中实现字符串分割--split
- SUDTOJ 3323园艺问题 (线段树)
- iOS 图片循环滚动(切片效果)
- SSM框架搭建
- Ubuntu16.04+hadoop2.7.3环境搭建
- linux 防火墙 iptables实例讲解
- js智能提示代码
- 数据挖掘_wget整站下载
- 解决xshell评估期已过的问题
- UNIX网络编程——处理服务器中大量的TIME_WAIT
- C#爬虫使用代理刷csdn文章浏览量
- docker容器下mysql更改WordPress的site address和home(URL)------局域网
- Hadoop项目实战-用户行为分析之应用概述(一)
- 2018.11.01 NOIP训练 梭哈(模拟)
- NodeJS之Mac初体验
- HDUOJ----专题训练C
- VI打开和编辑多个文件的命令
- 使用explain分析sql语句
- apache kafka监控系列-KafkaOffsetMonitor(转)
- 按键精灵saystring无法使用的几种解决方案