CFile::Seek

Repositions the pointer in a previously opened file.

virtual ULONGLONG Seek(
   LONGLONG lOff,
   UINT nFrom 
);

Parameters

  • lOff
    Number of bytes to move the pointer.

  • nFrom
    Pointer movement mode. Must be one of the following values:

    • CFile::begin   Move the file pointer lOff bytes forward from the beginning of the file.

    • CFile::current   Move the file pointer lOff bytes from the current position in the file.

    • CFile::end   Move the file pointer lOff bytes from the end of the file. Note that lOff must be negative to seek into the existing file; positive values will seek past the end of the file.

Return Value

If the requested position is legal, Seek returns the new byte offset from the beginning of the file. Otherwise, the return value is undefined and a CFileException object is thrown.

Remarks

The Seek function permits random access to a file's contents by moving the pointer a specified amount, absolutely or relatively. No data is actually read during the seek. If the requested position is larger than the size of the file, the file length will be extended to that position, and no exception will be thrown.

When a file is opened, the file pointer is positioned at offset 0, the beginning of the file.

Example

CFile cfile;
cfile.Open(_T("Seek_File.dat"), CFile::modeCreate |
   CFile::modeReadWrite);
LONGLONG lOffset = 1000;
ULONGLONG lActual;
lActual = cfile.Seek(lOffset, CFile::begin);

Requirements

Header: afx.h

See Also

Concepts

CFile Class

CFile Members

Hierarchy Chart