Input and Output Continuation
Input and Output Continuation
(CONTINUATION)
Checking Stateflags?
Get and Put Stream Positioning?
WHAT IS STREAM?
C++ uses a convenient abstraction called streams to perform
input and output operations in sequential media such as the
screen, the keyboard or a file. A stream is an entity where a
program can either insert or extract characters to/from.
There is no need to know details about the media associated to
the stream or any of its internal specifications. All we need to
know is that streams are a source/destination of characters, and
that these characters are provided/accepted sequentially.
CHECKING STATE FLAGS
All i/o streams objects keep internally -at least- one internal position:
ifstream, like istream, keeps an internal get position with the location of
the element to be read in the next input operation.
ofstream, like ostream, keeps an internal put position with the location
where the next element has to be written.
Finally, fstream, keeps both, the get and the put position, like iostream.
THESE INTERNAL STREAM POSITIONS POINT TO THE LOCATIONS WITHIN THE
STREAM WHERE THE NEXT READING OR WRITING OPERATION IS PERFORMED. THESE
POSITIONS CAN BE OBSERVED AND MODIFIED USING THE FOLLOWING MEMBER
FUNCTIONS:
seekg ( position );
seekp ( position );
Using this prototype, the stream pointer is changed
to the absolute position position (counting from the
beginning of the file). The type for this parameter
is streampos, which is the same type as returned by
functions tellg and tellp.
The other form for these functions is: