Using C and C++ standard streams and redirection
The standard streams are declared in the C header file stdio.h or in the C++ header files iostream.h or iostream. Table 1 shows the C standard streams and the functions that use them. Table 2 shows the C++ standard streams and the operators typically used to perform I/O with them.
cout << n << endl;
- z/OS XL C/C++ Runtime Library Reference discusses the C I/O stream functions.
- Standard C++ Library Reference discusses the Standard C++ I/O stream classes.
Stream name | Purpose | Functions that use it |
---|---|---|
stdin | The input device from which your C program usually retrieves its data. | getchar() |
stdout | The output device to which your C program normally directs its output. | printf() |
stderr | The output device to which your C program directs its diagnostic messages. z/OS® XL C/C++ uses stderr to collect error messages about exceptions that occur. | perror() |
Stream name | Purpose | Common usage |
---|---|---|
cin | The object from which your C++ program usually retrieves its data. In z/OS XL C++, input from cin comes from stdin by default. | >>, the input (extraction) operator |
cout | The object to which your C++ program normally directs its output. In z/OS XL C++, output to cout goes to stdout by default. | <<, the output (insertion) operator |
cerr | The object to which your C++ program normally directs its diagnostic messages. In z/OS XL C++, output to cerr goes to stderr by default. cerr is unbuffered, so each character is flushed as you write it. | <<, the output (insertion) operator |
clog | Another object intended for error messages. In z/OS XL C++, output to clog goes to stderr by default. Unlike cerr, clog is buffered. | <<, the output (insertion) operator |
On I/O operations requiring a file pointer, you can use stdin, stdout, or stderr in the same manner as you would any other file pointer.
printf("%d\n",n);
By default, stdin interprets the character sequence /* as indicating that the end of the file has been reached. See Performing terminal I/O operations for more information.