CW *_* II 12 c++ boost-iostreams
Boost C++库具有Function Template tee
类模板tee_filter和tee_device提供了两种分割输出序列的方法,以便将所有数据同时定向到两个不同的位置.
我正在寻找一个完整的C++示例,使用Boost tee输出到标准输出和像"sample.txt"这样的文件.
Mat*_*hen 26
基于John链接的问题的帮助:
#include <boost/iostreams/tee.hpp>
#include <boost/iostreams/stream.hpp>
#include <fstream>
#include <iostream>
using std::ostream;
using std::ofstream;
using std::cout;
namespace bio = boost::iostreams;
using bio::tee_device;
using bio::stream;
int main()
{
typedef tee_device<ostream, ofstream> TeeDevice;
typedef stream<TeeDevice> TeeStream;
ofstream ofs("sample.txt");
TeeDevice my_tee(cout, ofs);
TeeStream my_split(my_tee);
my_split << "Hello, World!\n";
my_split.flush();
my_split.close();
}
Run Code Online (Sandbox Code Playgroud)