0
void method(std::ostream &output){
     cout << "some text";
}

int main(){
      method(std::cout);
}

This gets added to my file when I run my program like this ./program arg > file.txt

How can I run this program so that this prints out to the file but also has separate printing for the console?

user1809913
  • 1,785
  • 1
  • 14
  • 25
  • Possible duplicates: [here](http://stackoverflow.com/q/8220956/596781) and [here](http://stackoverflow.com/q/1760726/596781). – Kerrek SB Jul 02 '13 at 01:26

1 Answers1

0

The easiest (non-)answer is not to bother inside your own program, but instead use a dedicated tool like tee:

./program arg | tee file.txt

If you want something finer-grained, you'll need to build in some equivalent logic into your program, e.g. using Boost tee.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • 1
    On windows there is http://gnuwin32.sourceforge.net/packages/coreutils.htm which has tee for windows. – scaryrawr Jul 02 '13 at 01:22
  • Thank you. I need to print different output to the console than to the file so boost tee is probably the way to go. – user1809913 Jul 02 '13 at 16:11