C++&引用;“你好,世界”;Boost-tee示例程序 Boost C++库具有

C++&引用;“你好,世界”;Boost-tee示例程序 Boost C++库具有,c++,boost-iostreams,C++,Boost Iostreams,类模板tee_filter和tee_device提供了两种分割输出序列的方法 因此,所有数据将同时定向到两个不同的位置 我在寻找一个完整的C++示例,使用Boost TEE输出到标准输出,然后到一个文件“Stask.txt”。< P>基于约翰链接的问题: #include <boost/iostreams/tee.hpp> #include <boost/iostreams/stream.hpp> #include <fstream> #include <

类模板tee_filter和tee_device提供了两种分割输出序列的方法 因此,所有数据将同时定向到两个不同的位置


我在寻找一个完整的C++示例,使用Boost TEE输出到标准输出,然后到一个文件“Stask.txt”。

< P>基于约翰链接的问题:

#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();
}
#包括
#包括
#包括
#包括
使用std::ostream;
使用std::of流;
使用std::cout;
名称空间bio=boost::iostreams;
使用bio::tee_装置;
使用bio::stream;
int main()
{
typedef T_装置T装置;
typedef-stream;
ofs流(“sample.txt”);
T设备我的T设备(cout,ofs);
TeeStream my_split(我的tee);

my_split下面是一个使用
tee_filter
的示例,我当前正在使用它来测试Boost。测试输出:

{ // init code, use static streams to keep them alive until test run process end

    using namespace boost::iostreams;
    static ofstream ofs("boost_test_output.log.xml"); // log file
    static tee_filter<ostream>  fileFilt(ofs); // tee all passed data to logfile

    // note derives from `boost::iostreams::output_filter`
    static text_xml_readability_filter xmlFilt; // filter all passed data, making the XML output readable

    static filtering_ostream filter; // master filter

    filter.push(fileFilt); // 1st, tee off any data to the file (raw boost XML)
    filter.push(xmlFilt);  // 2nd make the xml data stream readable (linebreaks, etc.)
    filter.push(cout);     // 3rd output the readable XML to cout

    boost::unit_test::unit_test_log.set_stream( filter );
}
{//init code,使用静态流使它们保持活动状态,直到测试运行进程结束
使用名称空间boost::iostreams;
ofs流的静态(“boost_test_output.log.xml”);//日志文件
静态tee_filter fileFilt(ofs);//将所有传递的数据tee到日志文件
//注释源自“boost::iostreams::output_filter”`
静态文本\u xml\u可读性\u filter xmlFilt;//过滤所有传递的数据,使xml输出可读
静态筛选\u ostream筛选器;//主筛选器
filter.push(fileFilt);//首先,将所有数据输入文件(原始boostxml)
filter.push(xmlFilt);//使xml数据流可读(换行符等)
filter.push(cout);//将可读的XML输出到cout
boost::单元测试::单元测试日志。设置流(过滤器);
}

boost tee是什么意思?(不完全是dupe)有一个例子。tee是boostAny链接中的库之一?我找不到任何相关的东西。可能只有我一个人