Stream Processing

Input and output are mapped into logical data streams, either text or binary. Streams present a consistent view of file contents, independent of the underlying file system. IBM C and C++ Compilers provides I/O buffering to increase the efficiency of system level I/O.

Text Streams
Text streams contain printable characters and control characters organized into lines. Each line consists of zero or more characters and ends with a new-line character (\n). A new-line character is not automatically appended to the end of the file.

Data read from a text stream is equal to the data that was written if it consists only of printable characters and the horizontal tab, new-line, vertical tab, and form-feed control characters. However, the compiler may add, alter, or ignore some new-line characters during input or output so that they conform to the conventions for representing text in the operating system environment. Thus, there may not be an exact correspondence between the characters in a stream and those in the output.

On output, each new-line character is translated into a carriage-return character, followed by a line-feed character. On input, a line-feed character or a carriage-return character followed by a line-feed character is converted to a new-line character.

When a text stream is connected to a character device, such as the keyboard or an operating system pipe, the Ctrl-Z (\x1a) character is treated as an end-of-file indicator, regardless of where it appears in the stream.

Binary Streams A binary stream is a sequence of characters or data. The data is not altered on input or output, so the data read from a binary stream is equal to the data that was written.

The Ctrl-Z character is treated like any other character and does not indicate end-of-file.



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


Considerations for Programming Stream I/O
File Handles for Standard Streams
I/O Buffering
Example of Storing Data in Text and Binary Streams
File Options Used with Data Definition Names