File - Wrapper for stdio streams
class provides a simple wrapper around stdio streams for use
It provides two kinds of convenience:
Firstly, constructors and destructors manage opening and closing of the stream.
The stream is checked for errors on closing, and the default behavior
is to exit() with an error message if a problem was found.
Secondly, the getline() method can be used for line-oriented input.
It strips comments and keeps track of input line
numbers for error reporting.
- File(const char *name, const char *mode, int exitOnError = 1)
- File(FILE *fp = 0, int exitOnError = 1)
A File object can be initialized with either a filename or an existing
In the first case, the file is opened according to mode
(as if by
The exitOnError flag determines whether I/O errors should be treated
Destroying a File object implies closing the associated stream.
- char *getline()
Returns the next line from the input, stored in a static buffer of
up to maxLineLength characters.
Empty lines and lines starting with # are skipped.
- int close()
Closes the stream without destroying the File object.
Returns non-zero is an error condition occurs.
- int error()
Returns a non-zero value if an error condition occurred on the stream.
- operator FILE *()
A File object can be cast to FILE * to access the underlying stdio
- ostream &position(ostream &stream = cerr)
Outputs the current line number on stream.
The stream is returned so it can be used as the left operand
of the << operator.
- const char *name
The filename used in creating the File object.
- const unsigned lineno
The current line number as maintained by getline().
- int exitOnError
When set to true this causes errors on the
stream to be handled by program termination (after printing an
Many other potentially useful functions are not provided (yet).
Andreas Stolcke <email@example.com>.
Copyright 1995, 1996 SRI International