Node:Files, Next:, Previous:Basics, Up:Usage



Files

For the most part, you will want to use libbinio to access normal binary files on your filesystem.

This is what the binfstream related classes are for. To use them, you first have to include the file binfile.h within your code.

This file contains four class declarations - binfbase, binifstream, binofstream and binfstream. binfbase is a base class for the others and normally not used by an ordinary libbinio user. This leaves us with three usable classes.

To create a binary stream on a file, just instantiate one of the three classes, according to what I/O facilities the stream should provide (see Basics for information on the class naming conventions).

To open a file, you use the open(filename, [mode]) method of one of the classes. filename is a string (both C style ASCIIZ strings and STL string objects can be passed, if supported by your compiler) containing the name of the file to open. Additionally, you can pass a mode argument to specify a special way to open the file - this is described later. There's also a special constructor, provided for convenience, that opens up a file automatically when the object is created. It has exactly the same syntax as open().

After usage, you can explicitly close the file with the close() method. It is always a good idea to do this explicitly, though not needed because the file automatically will be closed on object deconstruction.