Class RWFile also has member functions to determine the status of a file, and to read and write a wide variety of built-in types, either one at a time, or as arrays. The file pointer may be repositioned with functions SeekTo(), SeekToBegin(), and SeekToEnd(). The details of the RWFile class capabilities are summarized in the Class Reference.
The following example creates an RWFile with filename test.dat. The code reads an int (if the file is not empty), increments it, and writes it back to the file:
#include <rw/rwfile.h> main(){ RWFile file("test.dat"); // Construct the RWFile. // Check that the file exists, and that it has // read/write permission: if ( file.Exists() ) { int i = 0; // Read the int if the file is not empty: if ( !file.IsEmpty() ) file.Read(i); i++; file.SeekToBegin(); file.Write(i); // Rewrite the int. } return 0; }