home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
gnu
/
libg++-2.6.2.lha
/
libg++-2.6.2
/
libio
/
iostream.info-1
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-12-15
|
51KB
|
999 lines
This is Info file iostream.info, produced by Makeinfo-1.55 from the
input file ./iostream.texi.
START-INFO-DIR-ENTRY
* iostream: (iostream). The C++ input/output facility.
END-INFO-DIR-ENTRY
This file describes libio, the GNU library for C++ iostreams and C
stdio.
libio includes software developed by the University of California,
Berkeley.
Copyright (C) 1993 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided also
that the entire resulting derived work is distributed under the terms
of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions.
File: iostream.info, Node: Top, Next: Introduction, Prev: (DIR), Up: (DIR)
The GNU C++ Iostream Library
****************************
This file provides reference information on the GNU C++ iostream
library (`libio'), version 0.64.
* Menu:
* Introduction::
* Operators:: Operators and default streams.
* Streams:: Stream classes.
* Files and Strings:: Classes for files and strings.
* Streambuf:: Using the streambuf layer.
* Stdio:: C input and output.
* Index::
File: iostream.info, Node: Introduction, Next: Operators, Prev: Top, Up: Top
Introduction
************
The iostream classes implement most of the features of AT&T version
2.0 iostream library classes, and most of the features of the ANSI X3J16
library draft (which is based on the AT&T design).
This manual is meant as a reference; for tutorial material on
iostreams, see the corresponding section of any recent popular
introduction to C++.
* Menu:
* Copying:: Special GNU licensing terms for libio.
* Acknowledgements:: Contributors to GNU iostream.
File: iostream.info, Node: Copying, Next: Acknowledgements, Up: Introduction
Licensing terms for `libio'
===========================
Since the `iostream' classes are so fundamental to standard C++, the
Free Software Foundation has agreed to a special exception to its
standard license, when you link programs with `libio.a':
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does
not cause the resulting executable to be covered by the GNU
General Public License. This exception does not however
invalidate any other reasons why the executable file might be
covered by the GNU General Public License.
The code is under the GNU General Public License (version 2) for all
other purposes than linking with this library; that means that you can
modify and redistribute the code as usual, but remember that if you do,
your modifications, and anything you link with the modified code, must
be available to others on the same terms.
These functions are also available as part of the `libg++' library;
if you link with that library instead of `libio', the GNU Library
General Public License applies.
File: iostream.info, Node: Acknowledgements, Prev: Copying, Up: Introduction
Acknowledgements
================
Per Bothner wrote most of the `iostream' library, but some portions
have their origins elsewhere in the free software community. Heinz
Seidl wrote the IO manipulators. The floating-point conversion software
is by David M. Gay of AT&T. Some code was derived from parts of BSD
4.4, which was written at the University of California, Berkeley.
The iostream classes are found in the `libio' library. An early
version was originally distributed in `libg++', and they are still
included there as well, for convenience if you need other `libg++'
classes. Doug Lea was the original author of `libg++', and some of the
file-management code still in `libio' is his.
Various people found bugs or offered suggestions. Hongjiu Lu worked
hard to use the library as the default stdio implementation for Linux,
and has provided much stress-testing of the library.
File: iostream.info, Node: Operators, Next: Streams, Prev: Introduction, Up: Top
Operators and Default Streams
*****************************
The GNU iostream library, `libio', implements the standard input and
output facilities for C++. These facilities are roughly analogous (in
their purpose and ubiquity, at least) with those defined by the C
`stdio' functions.
Although these definitions come from a library, rather than being
part of the "core language", they are sufficiently central to be
specified in the latest working papers for C++.
You can use two operators defined in this library for basic input and
output operations. They are familiar from any C++ introductory
textbook: `<<' for output, and `>>' for input. (Think of data flowing
in the direction of the "arrows".)
These operators are often used in conjunction with three streams that
are open by default:
- Variable: ostream cout
The standard output stream, analogous to the C `stdout'.
- Variable: istream cin
The standard input stream, analogous to the C `stdin'.
- Variable: ostream cerr
An alternative output stream for errors, analogous to the C
`stderr'.
For example, this bare-bones C++ version of the traditional "hello"
program uses `<<' and `cout':
#include <iostream.h>
int main(int argc, char **argv)
{
cout << "Well, hi there.\n";
return 0;
}
Casual use of these operators may be seductive, but--other than in
writing throwaway code for your own use--it is not necessarily simpler
than managing input and output in any other language. For example,
robust code should check the state of the input and output streams
between operations (for example, using the method `good'). *Note
Checking the state of a stream: States. You may also need to adjust
maximum input or output field widths, using manipulators like `setw' or
`setprecision'.
- Operator on ostream: <<
Write output to an open output stream of class `ostream'. Defined
by this library on any OBJECT of a C++ primitive type, and on
other classes of the library. You can overload the definition for
any of your own applications' classes.
Returns a reference to the implied argument `*this' (the open
stream it writes on), permitting statements like
cout << "The value of i is " << i << "\n";
- Operator on istream: >>
Read input from an open input stream of class `istream'. Defined
by this library on primitive numeric, pointer, and string types;
you can extend the definition for any of your own applications'
classes.
Returns a reference to the implied argument `*this' (the open
stream it reads), permitting multiple inputs in one statement.
File: iostream.info, Node: Streams, Next: Files and Strings, Prev: Operators, Up: Top
Stream Classes
**************
The previous chapter referred in passing to the classes `ostream'
and `istream', for output and input respectively. These classes share
certain properties, captured in their base class `ios'.
* Menu:
* Ios:: Shared properties.
* Ostream:: Managing output streams.
* Istream:: Managing input streams.
* Iostream:: Input and output together.
File: iostream.info, Node: Ios, Next: Ostream, Up: Streams
Shared properties: class `ios'
==============================
The base class `ios' provides methods to test and manage the state
of input or output streams.
`ios' delegates the job of actually reading and writing bytes to the
abstract class `streambuf', which is designed to provide buffered
streams (compatible with C, in the GNU implementation). *Note Using
the `streambuf' layer: Streambuf, for information on the facilities
available at the `streambuf' level.
- Constructor: ios::ios ([streambuf* SB [, ostream* TIE])
The `ios' constructor by default initializes a new `ios', and if
you supply a `streambuf' SB to associate with it, sets the state
`good' in the new `io