file::GetPosition

Description

Get the current value of the file pointer which is an offset from the beginning of the file.

Syntax

LONG GetPosition( )

Parameters

Return

Returns the current value of the file pointer.

Examples

EX1

void file_GetPosition_ex1()
{
    char szTemp[MAXFULLPATH];
    GetTempPath(MAXFULLPATH, szTemp); // Get temp folder path.
    string strFile = szTemp + "\\test.txt";
    file ff;
    if( ff.Open(strFile, file::modeCreate | file::modeWrite) )
    {
        int i = 10;
        int ia[4] = {1, 2, 3, 4};
        LONG lPosition;
        
        ff.Write(&i, sizeof(i));        // Write 1 int (4 bytes) to file.
        lPosition = ff.GetPosition();    // Position now equals 4. 
        ff.Write(ia, sizeof(ia));        // Write 4 ints (16 bytes) to file following previous int.
        lPosition = ff.GetPosition();    // Position now equals 20.
        ff.SeekToBegin();                // Set file pointer to start of file.
        lPosition = ff.GetPosition();    // Position now equals 0.
        ff.Close();
    }
}

Remark

See Also

file::Seek

Header to Include

origin.h