file::ReadFloat

Description

Syntax

UINT ReadFloat( void * pDestBuffer, int nDataTypeSize, UINT nItemCount, BOOL bIsLittleEndian = TRUE )

Parameters

pDestBuffer
[output] Destination's buffer of store the int value
nDataTypeSize
[input] Must be size of datatype, for integal, 1, 2 and 4, for float. 4 and 8.
nItemCount
[input] Number of data;
bIsLittleEndian
[input] TRUE, use Little Endian way, FALSE use Big Endian way, default value is TRUE.

Return

The number of items read from file.

Examples

EX1

void file_ReadFolat_ex1()
{
    file ff;   
    string strFile = "readwritefloat.dat";  
    BOOL bOK = ff.Open(strFile, file::modeCreate | file::modeWrite);
    if(!bOK)
        out_str("Could not open the \\readwritefloat.dat file.");

        //Write float
    vector<float> vecfloat={2,4,6,8};
    vector<double> vecdouble={1,3,5,7};
    ff.WriteFloat(&vecfloat,sizeof(float),vecfloat.GetSize());
    ff.WriteFloat(&vecdouble, sizeof(double), vecdouble.GetSize(), false);
    ff.Close();

    bOK = ff.Open(strFile, file::modeRead);
    if(!bOK)
        out_str("Could not open the \\readwritefloat.dat file.");

        //Read float
    vector<float> vecf2(4);
    vector<double> vecd2(4);
    ff.ReadFloat(&vecf2,sizeof(float),vecfloat.GetSize());
    ff.ReadFloat(&vecd2,sizeof(double), vecdouble.GetSize(),false);
 
    for(int i=0;i<4;i++)
        printf("%f\t%f\n",vecf2[i],vecd2[i]);
    ff.Close();
}

Remark

See Also

file::ReadInt, file::WriteFloat

Header to Include

origin.h