Rogue Wave Banner

Click on the banner to return to the user guide home page.

©Copyright 1996 Rogue Wave Software

Chapter 7: Using Class RWFile

Class RWFile encapsulates the standard C file operations for binary read and write, using the ANSI-C functions fopen(), fwrite(), fread(), etc. This class is patterned on class PFile of the Interviews Class Library (Stanford University, 1987), but has been modernized by Rogue Wave to use const modifiers, and to port to various operating systems. The member function names begin with upper case letters in order to maintain compatibility with class PFile.

The constructor for class RWFile has the prototype:

RWFile(const char* filename, const char* mode = 0);

This constructor will open or create a binary file called filename with mode set to mode (for example, r+), as defined by the Standard C function fopen(). If mode is zero, which is the default, an existing file will be opened for update (mode r+ for UNIX, rb+ for Windows environments). If filename does not exist, it will be created (mode w+ for UNIX, wb+ for Windows environments). The destructor for this class closes the file.

After constructing an RWFile, you should use member function isValid() to check whether opening the file was successful.

There are member functions to flush the file, and to test whether the file has had an error, or is empty or at the end-of-file.


Previous file Table of Contents Next file