#include "bitstream.h"

class ofbitstream : public obitstream

This class writes bits of data to input files. This class inherits from the obitstream class.

Available since: 2014/02/01 version of C++ library

Constructors
ofbitstream()  Constructs a new bit stream that is not attached to any file.
ofbitstream(filename)  Constructs a new bit stream that writes to the specified file.
Methods
close()  Closes the currently-opened file, if the stream is open.
open(filename)  Opens the specified file for writing.
writeBit()  Writes a single bit to the bit stream.

Constructor detail


ofbitstream();
Constructs a new bit stream that is not attached to any file. You can open a file for writing using the open member function.

Usage:

ofbitstream stream;

ofbitstream(const char* filename);
ofbitstream(string filename);
Constructs a new bit stream that writes to the specified file, if it exists. Any previous contents of the file are overwritten. If the file does not exist, the stream enters an error state.

Usage:

ofbitstream stream(filename);

Method detail


void close();
Closes the currently-opened file, if the stream is open. If the stream is not open, puts the stream into a fail state.

Usage:

stream.close();

void open(const char* filename);
void open(string filename);
Opens the specified file for writing. Any previous contents of the file are overwritten. If an error occurs, the stream enters a failure state, which can be detected by calling the fail member function.

Usage:

stream.open(filename);

void writeBit(int bit);
Writes a single bit to the obitstream. Raises an error if this bit stream has not been properly opened. Also raises an error if the value passed for the bit parameter is not 0 or 1. (Note: A common bug is to pass a char value of '0' or '1'; these are character literals that have the ASCII integer values of 48 and 49 respectively. The char values of '0' and '1' are not the same as the int values 0 and 1.)

Usage:

stream.writeBit(bit);