#include #include using std::cout; using std::cin; void main( void ) { std::ifstream input( "input.txt" ); // copy the file's output buffer to standard out cout << input.rdbuf(); cout << "\nType until you're done (^Z) -\n"; cout << cin.rdbuf(); // Josuttis, p683 cout << "\nType until you're done (^Z) -\n"; cin >> std::noskipws >> cout.rdbuf(); // Josuttis, p684 std::ofstream output( "output.txt" ); // save output buffer of standard out Josuttis, p641 std::streambuf* rdbuf_save = cout.rdbuf(); // redirect standard out to the file cout.rdbuf( output.rdbuf() ); output << "one row for the file\n"; cout << "one row for standard out\n"; // reinstate standard out's output buffer cout.rdbuf( rdbuf_save ); output.close(); cout << "\nbefore system call\n"; system( "type output.txt" ); } // 1 - 1234567890 1234567890 1234567890 1234567890 1234567890 // 2 - 1234567890 1234567890 1234567890 1234567890 1234567890 // 3 - 1234567890 1234567890 1234567890 1234567890 1234567890 // 4 - 1234567890 1234567890 1234567890 1234567890 1234567890 // 5 - 1234567890 1234567890 1234567890 1234567890 1234567890 // // Type until you're done (^Z) - // now is this time // now is this time // for all good men // for all good men // ^Z // // Type until you're done (^Z) - // the quick brown fox // the quick brown fox // jumped over the lazy dog // jumped over the lazy dog // ^Z // // before system call // one row for the file // one row for standard out