Tools.h++ Manual

21-110 104011 Tandem Computers Incorporated
21
RWFile
Synopsis
#include <rw/rwfile.h>
RWFile f("filename");
Description Class
RWFile
encapsulates binary file operations using the Standard C stream
library (functions
fopen(), fread(), fwrite(),
etc.). This class is based
on class
PFile
of the Interviews Class Library (1987, Stanford University). The
member function names begin with upper case letters in order to maintain
compatibility with class
PFile
.
Because this class is intended to encapsulate binary operations, it is important
that it be opened using a binary mode. This is particularly important under
MS-DOS—otherwise bytes that happen to match a newline will be expanded to
(carriage return, line feed).
Public constructors
RWFile(const char* filename, const char* mode = 0);
Construct an
RWFile
to be used with the file of name
filename
and with
mode
mode
. The mode is as given by the Standard C library function
fopen()
. If
mode
is zero (the default) then the constructor will attempt to
open an existing file with the given filename for update (mode "
rb+
"). If this is
not possible, then it will attempt to create a new file with the given filename
(mode "
wb+
"). The resultant object should be checked for validity using
function
isValid()
.
~RWFile();
Performs any pending I/O operations and closes the file.
Public member functions
long CurOffset();
Returns the current position, in bytes from the start of the file, of the file
pointer.
RWBoolean Eof();
Returns
TRUE
if an end-of-file has been encountered.
RWBoolean Erase();
Erases the contents but does not close the file. Returns
TRUE
if the operation
was successful.