| 1 |
#include <string> |
| 2 |
#include <iostream> |
| 3 |
#include <istream> |
| 4 |
#include "fdout.h" |
| 5 |
using namespace std; |
| 6 |
|
| 7 |
int main(int argc, char **argv) |
| 8 |
{ |
| 9 |
OFdnStreambuf fds(STDOUT_FILENO, 500); |
| 10 |
ostream os(&fds); |
| 11 |
|
| 12 |
switch (argc) |
| 13 |
{ |
| 14 |
case 1: |
| 15 |
for (string s; getline(cin, s); ) |
| 16 |
os << s << '\n'; |
| 17 |
os << "COPIED cin LINE BY LINE\n"; |
| 18 |
break; |
| 19 |
|
| 20 |
case 2: |
| 21 |
cin >> os.rdbuf(); // Alternatively, use: cin >> &fds; |
| 22 |
os << "COPIED cin BY EXTRACTING TO os.rdbuf()\n"; |
| 23 |
break; |
| 24 |
|
| 25 |
case 3: |
| 26 |
os << cin.rdbuf(); |
| 27 |
os << "COPIED cin BY INSERTING cin.rdbuf() into os\n"; |
| 28 |
break; |
| 29 |
} |
| 30 |
} |