fork(2) download
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. struct MyStreamingHelper
  5. {
  6. MyStreamingHelper(std::ostream& out1,
  7. std::ostream& out2) : out1_(out1), out2_(out2) {}
  8. std::ostream& out1_;
  9. std::ostream& out2_;
  10. };
  11.  
  12. template <typename T>
  13. MyStreamingHelper& operator<<(MyStreamingHelper& h, T const& t)
  14. {
  15. h.out1_ << t;
  16. h.out2_ << t;
  17. return h;
  18. }
  19.  
  20. MyStreamingHelper& operator<<(MyStreamingHelper& h, std::ostream&(*f)(std::ostream&))
  21. {
  22. h.out1_ << f;
  23. h.out2_ << f;
  24. return h;
  25. }
  26.  
  27. int main()
  28. {
  29. std::ofstream fl;
  30. fl.open("test.txt");
  31. MyStreamingHelper h(fl, std::cout);
  32. h << "!!!Hello World!!!" << std::endl << std::flush;
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 15224KB
stdin
Standard input is empty
stdout
!!!Hello World!!!