在C ++或库中有一个空的std :: ostream实现? [英] Is there a null std::ostream implementation in C++ or libraries?

查看:428
本文介绍了在C ++或库中有一个空的std :: ostream实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一个 / dev / null std :: ostream 实现。它只会忽略流向它的任何东西。这样的事情存在于标准库还是Boost?

I'm looking for a std::ostream implementation that acts like /dev/null. It would just ignore anything that is streamed to it. Does such a thing exist in the standard libraries or Boost? Or do I have to roll my own?

推荐答案

如果你有boost,那么就有一个null ostream& istream实现在boost / iostreams / device / null.hpp中可用。其要点:

If you have boost, then there's a null ostream & istream implementation available in boost/iostreams/device/null.hpp . The gist of it:

#include "boost/iostreams/stream.hpp"
#include "boost/iostreams/device/null.hpp"
...
boost::iostreams::stream< boost::iostreams::null_sink > nullOstream( ( boost::iostreams::null_sink() ) );
...

这篇关于在C ++或库中有一个空的std :: ostream实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆