Using Standard Streams
Standard streams are supported by the C library and the C++
iostream library.
To use the C standard streams, include the header <stdio.h>.
The standard streams are not available when you are using the subsystem libraries.
On input and output operations requiring a file pointer, you can use the standard streams in the same manner as you would a regular file pointer.
Do not code your program so that it is dependent on the association of file handles to streams, because handles can be associated with different streams.
If you are running your program under OS/2
Presentation Manager, you must redirect the standard
output streams to see the output.
The standard streams are always in text mode at the start of your program. You can change the mode to binary or back to text, without redirecting the stream, by calling the freopen function with no file name specified. You cannot change the mode only to text or binary, and the file type must be disk. No other parameters are allowed. This method is not included in the ANSI C standard. For example, the following statement makes stdin a binary stream:
fp = freopen("", "rb", stdin);
Using Files
To perform stream I/O on files, use the C++ input/output library
or run-time library functions.
When you open a file in append mode, the file pointer is positioned at the end of the file.
When you connect a text stream to a character device, use the Ctrl-Z character as an end-of-file marker. If the last character of a file accessed by a text stream is Ctrl-Z, the Ctrl-Z is discarded when it is read or when the file is opened in append or update mode. IBM C and C++ Compilers does not automatically append Ctrl-Z to a file when the file is closed. If you require a Ctrl-Z character at the end of your text files, you must write it out yourself.
IBM C and C++ Compilers supports memory files, which
are temporary files that reside in memory. You can write to and
read from a memory file just as you do with a disk file. Using
memory files can speed program execution by reducing disk I/O.
You can use data definition names (ddnames) to change the files accessed by your program on each run, without having to change the code or pass filenames as arguments to main.
Limitations
IBM C and C++ Compilers does not support record level
I/O.
You cannot call the ftell , fseek, fgetpos, fsetpos, and rewind functions to get or change the file position within character devices or operating system pipes.
You cannot seek past the end of a text file. Seeking past the end of a binary file that was opened in mode w, w+, wb+, w+b, or wb, creates a new end-of-file position and writes nulls between the old end-of-file position and the new one.
IBM C and C++ Compilers for OS/2 does not support
pipes that are created with the API DosCreateNpipe. Also, it does
not let you seek within character devices or piped files.
![]()
Stream
Processing
Standard
Streams
![]()
Redirect
Standard Streams
Direct I/O to Memory Files
Open Streams using Data Definition Names
View Output
to Standard Streams from PM Programs
![]()
I/O Buffering
File Handles for
Standard Streams
Example of Storing Data in Text and Binary Streams