## wxFFile

wxFFile implements buffered file I/O. This is a very small class designed to minimize the overhead of using it - in fact, there is hardly any overhead at all, but using it brings you automatic error checking and hides differences between platforms and compilers. It wraps inside it a `FILE *` handle used by standard C IO library (also known as `stdio`).

Derived from

None.

Include files

<wx/ffile.h>

wxFromStart | Count offset from the start of the file
wxFromCurrent | Count offset from the current position of the file pointer
wxFromEnd | Count offset from the end of the file (backwards)

Members

wxFFile::wxFFile
wxFFile::~wxFFile
wxFFile::Attach
wxFFile::Close
wxFFile::Detach
wxFFile::fp
wxFFile::Eof
wxFFile::Flush
wxFFile::IsOpened
wxFFile::Length
wxFFile::Open
wxFFile::Read
wxFFile::Seek
wxFFile::SeekEnd
wxFFile::Tell
wxFFile::Write
wxFFile::Write

### wxFFile::wxFFile

wxFFile()

Default constructor.

wxFFile(const char* filename, const char* mode = "r")

Opens a file with the given mode. As there is no way to return whether the operation was successful or not from the constructor you should test the return value of IsOpened to check that it didn't fail.

wxFFile(FILE* fp)

Opens a file with the given file pointer, which has already been opened.

Parameters

filename

The filename.

mode

The mode in which to open the file using standard C strings.

fp

An existing file descriptor, such as stderr.

### wxFFile::~wxFFile

~wxFFile()

Destructor will close the file.

NB: it is not virtual so you should not derive from wxFFile!

### wxFFile::Attach

void Attach(FILE* fp)

Attaches an existing file pointer to the wxFFile object.

The descriptor should be already opened and it will be closed by wxFFile object.

### wxFFile::Close

bool Close()

Closes the file and returns TRUE on success.

### wxFFile::Detach

void Detach()

Get back a file pointer from wxFFile object - the caller is responsible for closing the file if this descriptor is opened. IsOpened() will return FALSE after call to Detach().

### wxFFile::fp

FILE * fp() const

Returns the file pointer associated with the file.

### wxFFile::Eof

bool Eof() const

Returns TRUE if the an attempt has been made to read past the end of the file.

Note that the behaviour of the file descriptor based class wxFile is different as wxFile::Eof will return TRUE here as soon as the last byte of the file has been read.

### wxFFile::Flush

bool Flush()

Flushes the file and returns TRUE on success.

### wxFFile::IsOpened

bool IsOpened() const

Returns TRUE if the file has been opened.

### wxFFile::Length

size_t Length() const

Returns the length of the file.

### wxFFile::Open

bool Open(const char* filename, const char* mode = "r")

Opens the file, returning TRUE if successful.

Parameters

filename

The filename.

mode

The mode in which to open the file.

### wxFFile::Read

size_t Read(void* buffer, off_t count)

Reads the specified number of bytes into a buffer, returning the actual number read.

Parameters

buffer

A buffer to receive the data.

count

The number of bytes to read.

Return value

The number of bytes read.

### wxFFile::Seek

bool Seek(long ofs, wxSeekMode mode = wxFromStart)

Seeks to the specified position and returs TRUE on success.

Parameters

ofs

Offset to seek to.

mode

One of wxFromStart, wxFromEnd, wxFromCurrent.

### wxFFile::SeekEnd

bool SeekEnd(long ofs = 0)

Moves the file pointer to the specified number of bytes before the end of the file and returns TRUE on success.

Parameters

ofs

Number of bytes before the end of the file.

### wxFFile::Tell

size_t Tell() const

Returns the current position.

### wxFFile::Write

size_t Write(const void* buffer, size_t count)

Writes the specified number of bytes from a buffer.

Parameters

buffer

A buffer containing the data.

count

The number of bytes to write.

Return value

Number of bytes written.

### wxFFile::Write

bool Write(const wxString& s)

Writes the contents of the string to the file, returns TRUE on success.