file

 

Contents

Name

file

Remark

The Origin C file class provides read/write access to binary files using unbuffered io (immediate disk access) similar to the MFC CFile class. See also the stdioFile class for buffered stream io to text files.

Hierarchy

Examples

EX1

//generate a binary file with 4 integer
void file_ex1()
{
    char szTemp[MAXFULLPATH];
    GetTempPath(MAXFULLPATH, szTemp); // Get temp folder path.
    string strFile = szTemp + "\\test.Dat";
    file ff(strFile, file::modeCreate | file::modeWrite); // Create a new write only file.
    int bb[4] = {1, 2, 3, 4};
    int iSize = sizeof(bb);
    ff.Write(bb,iSize);
    ff.Close();
}

EX2

//generate a binary file of unsigned short in the form of cell=r + c
//you can read this type of file into Origin with the impbin2d X-Function
void file_ex2(int nCols = 128, int nRows = 10)
{
    string strFile = GetAppPath() + "test" + nCols + "x" + nRows + ".img";
    file ff;
    if(ff.Open(strFile, file::modeCreate | file::modeWrite))
    {
        for(int ii = 0; ii < nRows; ii++)
        {
            for(int jj = 0; jj < nCols; jj++)
            {
                unsigned short us = ii + jj;
                ff.Write(&us, 2);
            }
        }
        ff.Close();
        printf("file successfully created:\n%s\n", strFile);
    }
    else
        printf("failed to create file:%s\n", strFile);
}

header to Include

origin.h

Reference

Members

Name Brief Example
Close Close the file associated with the indicated file object. Examples
file Set the public data member m_hFile to a null value. Examples
Flush Force data remaining in the file buffer to be written to the file. Examples
GetHandle Get the handle of current open file. Examples
GetLastError Get the value of the last error that occured. Examples
GetLength Obtains the current logical length of the file in bytes. Examples
GetPosition Get the current value of the file pointer which is an offset from the beginning of the file. Examples
IsOpen Check file object is open or not, when use a method of File object which is not open will lead a runtime error. Use this function before you call the method of File object. Examples
Open Open a file returning FALSE or 0 on failure and TRUE or a non-zero on success. Examples
Read Read data into a buffer from the file associated with the file object. Examples
ReadFloat Read a set of float data from file Examples
ReadInt It is used to support Little Endian and Big Endian read and write binary data. Examples
Seek Moves the pointer to the current file position as specified. Seek enables random access within a file. Examples
SeekToBegin Sets the file pointer value to the beginning of the file. This is the same as file::Seek(0, file::begin). Examples
SeekToEnd Sets the file pointer value to the end of the file. This is the same as file::Seek(0, file::end). Examples
Write Write data from a buffer into the file associated with the file object. Examples
WriteFloat Write a set of float data into file Examples
WriteInt Write a set of integer data into file Examples