yo/concrete/examples/noredir.cc
raw| 1 | #include <iostream> |
| 2 | #include <fstream> |
| 3 | #include <cstdlib> |
| 4 | using namespace std; |
| 5 | |
| 6 | int main() |
| 7 | { |
| 8 | ofstream of("outfile"); |
| 9 | |
| 10 | streambuf *buf = cout.rdbuf(of.rdbuf()); |
| 11 | cout << "To the of stream\n"; |
| 12 | system("echo hello world"); |
| 13 | cout << "To the of stream\n"; |
| 14 | cout.rdbuf(buf); |
| 15 | } |
| 16 | /* |
| 17 | Generated output: on the file `outfile' |
| 18 | |
| 19 | To the of stream |
| 20 | To the of stream |
| 21 | |
| 22 | On standard output: |
| 23 | |
| 24 | hello world |
| 25 | */ |