C ++“hello world” Boost tee示例程序 [英] C++ "hello world" Boost tee example program
本文介绍了C ++“hello world” Boost tee示例程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Boost C ++库中包含功能模板tee
The Boost C++ library has Function Template tee
类模板tee_filter和tee_device提供了两种方式来分割输出序列
,到两个不同的位置。
The class templates tee_filter and tee_device provide two ways to split an output sequence so that all data is directed simultaneously to two different locations.
我正在寻找一个完整的C ++示例使用Boost tee输出到标准输出,
I am looking for a complete C++ example using Boost tee to output to standard out and to a file like "sample.txt".
推荐答案
根据John链接的问题的帮助:
Based on help from the question John linked:
#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();
}
这篇关于C ++“hello world” Boost tee示例程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文