class cdebug_stream :public ostream
{
public:
typedef cdebug_stream& (*manip_fnptr)(cdebug_stream&);
void attach(ostream& os) { m_outs.push_back(&os); }
void detach(ostream& os) { m_outs.erase(std::remove(m_outs.begin(),m_outs.end(),&os),m_outs.end()); }
template<typename T>
cdebug_stream& operator << (T const& val) {
for(vector<ostream*>::iterator it = m_outs.begin();
it != m_outs.end();
++it)
(**it) << val;
return *this;
}
cdebug_stream& operator << (ostream& (*manip)(ostream&)) {
for(vector<ostream*>::iterator it = m_outs.begin();
it != m_outs.end();
++it)
(*manip)(**it);
return *this;
}
private:
vector<ostream*> m_outs;
} cdebug;
inherit the ostream
最新推荐文章于 2025-04-30 17:43:19 发布
本文详细介绍了cdebug_stream类的实现与使用方法,包括模板运算符重载、输出流附加与分离等功能,适用于日志输出与调试场景。

1204

被折叠的 条评论
为什么被折叠?



