/* * Produces output on stdout and stderr, prompts and reads from stdin. * * To compile and execute this file on Unix: * $ g++ -o stdxxx stdxxx.c++ * $ ./stdxxx * * -Ian! D. Allen - idallen@idallen.ca */ #include // cin, cout using namespace std; #define MYBUFSIZE 10 /* input buffer size in chars */ /* Command line arguments are ignored in this program. */ int main( int argc, char **argv ){ char buffer[MYBUFSIZE]; /* First, put some output on standard output. * The name of the program is put in argv[0] by the shell. */ cout << argv[0] << ": "; cout << "Hello World! appears on stdout.\n" ; /* Programs should always prompt for input on standard error: */ cerr << "Enter a short word: " ; /* Read a word from standard input: */ cin >> buffer; /* XXX - can get buffer overflow here */ /* Output the word on both standard error and standard output: */ cerr << "This output is on stderr: "; cerr << buffer; cerr << "\n"; cout << "This output is on stdout: "; cout << buffer; cout << "\n"; return 0; /* send good return status back to O/S */ }