2.2.5.1.10 file::Read

Description

Read data into a buffer from the file associated with the file object.

Syntax

UINT Read( void * lpBuf, UINT nCount )

Parameters

lpBuf
[output]A buffer where the data read is stored.
nCount
[input] The number of bytes to read from the file indicated by the file object.

Return

Number of bytes read from the file. May be less than nCount if EOF is reached.

Examples

EX1

int file_Read_ex1()
{
    file ff;
    bool bOK = ff.Open("c:\\test.txt", file::modeCreate | file::modeNoTruncate | file::modeRead);
    if(!bOK)
    {
        out_str("Failed to open file C:\test.txt");
        return 0;
    }
    int aa, intlist[4];
    ff.Read(&aa, sizeof(aa));
    ff.Read(intlist, sizeof(intlist));
    //ff.Read(&intlist[0], sizeof(intlist));
 
    //read double
    double bb;
    ff.Read(&bb, sizeof(bb));
 
    //read structure
    WIN32_FIND_DATAA cc;
    ff.Read(&cc, sizeof(cc));
 
    //read char array
    char dd[20];
    ff.Read(dd, sizeof(dd));
 
    //read vector
    vector<int> kk;
    kk.SetSize(5);
    int size = sizeof(int) * kk.GetSize();
    ff.Read(kk, size);
    return 1;            
}

EX2

//read data to the 1st column of active worksheet with dataset
//assume all datas are numeric
int file_Read_ex2()
{
    file ff;
    bool bOK = ff.Open("C:\\test.txt", file::modeCreate | file::modeNoTruncate | file::modeReadWrite);
    if(!bOK)
    {
        out_str("Failed to open file C:\test.txt");
        return 0;
    }
 
    Worksheet wks = Project.ActiveLayer();
    Column cc; 
    if(wks)
        cc = wks.Columns(0);
    else
		out_str("Iinvalid worksheet");
 
    //get data
    cc.SetInternalData(FSI_DOUBLE);
    Dataset ds(cc);
    int nDataSize = 5;
    ds.SetSize(nDataSize);
 
    //write data
    int nRead = ff.Read(ds, nDataSize * sizeof(double));
    return 1;            
}

Remark

See Also

File::Write

Header to Include

origin.h