(out_file,cout) << "\n\nTotal tokens found: " << statistics[0] << "\n\nAlphaNumeric Tokens: " << statistics[1] << "\n\nPunctuation character found: " << statistics[2] << "\nNumber of whitespace: " << statistics[3] << "\nNumber of newlines: " << statistics[4] << "\n\nTokens are stored in out file\n\nPress Enter to exit....";
那么数据是否同时应用于out_file和cout?
out_file是fstream ..
boost::iostreams::tee_device
将数据发送到一对流. teeing.cpp
#include <boost/iostreams/stream.hpp>#include <boost/iostreams/tee.hpp>#include <fstream>#include <iostream>int main(){ typedef boost::iostreams::tee_device<std::ostream,std::ostream> Tee; typedef boost::iostreams::stream<Tee> TeeStream; std::ofstream out_file("./out_file.log"); Tee tee(std::cout,out_file); TeeStream both(tee); both << "This is a test!" << std::endl;}
建立:
> clang++ -I/path/to/boost/1.54.0/include teeing.cpp -o teeing
跑:
> ./teeingThis is a test!
校验:
> cat ./out_file.log This is a test!总结
以上是内存溢出为你收集整理的c – 是否可以同时在两个对象上使用插入 *** 作符?全部内容,希望文章能够帮你解决c – 是否可以同时在两个对象上使用插入 *** 作符?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)