4694. CDataFile Class
- Functions and Usage
The main functions of CDataFile are shown in the following:
1. Create a file with two modes:
Function : BOOL CDataFile::CreateFile(LPCTSTR lpszFileName, UINT nFlags)
Usage: nFlags may be CREATE_MODE_REBUILD (Whether the file exists or not, recreate it) or CREATE_MODE_NOREBUILD (If the file has existed ,do not recreate it)
2. Open a file with three modes:
Function : BOOL CDataFile::OpenFile(LPCTSTR lpszFileName, UINT nFlags)
Usage: nFlags may be OPEN_MODE_READ ,OPEN_MODE_WRITE ,OPEN_MODE_READWRITE
3. Check a file whether it has exisited:
Function : INT CDataFile::CheckFileExsist(LPCTSTR lpszFileName)
Usage : Return values may be FLAG_FILE_EXIST , FLAG_FILE_NOEXIST
4. Get the number of lines in the file:
Function : UINT CDataFile::GetLines()
Usage : Return value is the number of lines.
5. Move the pointer to the line you want to operate:
Function : BOOL CDataFile::MoveToLine(UINT line)
Usage : If you want to use ReadLine() or WriteLine(),you must use MoveToLine() first.
6. Read the line you move to:
Function: BOOL CDataFile::ReadLine(CString &rString)
7. Insert, overwrite, delete a line at current line:
Function : void CDataFile::WriteLine(CString &wString, UINT nFlag)
Usage : nFlag may be WRITE_MODE_INSERT ,WRITE_MODE_OVERWRITE or WRITE_MODE_DELETE.If nFlag is WRITE_MODE_DELETE , the wString is the content of the line you will delete.
8. Close a file:
Function : void CDataFile::CloseFile()
CDataFile类
CDataFile类的主要函数如下:
1 创建一个文件的两种模式:
函数:BOOL CDataFile::CreateFile(LPCTSTR lpszFileName, UINT nFlags)
说明:nFlags可以是CREATE_MODE_REBUILD(无论这个文件存在与否,重新创建)或者CREATE_MODE_NOREBUILD(如果文件存在的话,就不创建)
2 三种模式打开一个文件:
函数 : BOOL CDataFile::OpenFile(LPCTSTR lpszFileName, UINT nFlags)
方法: nFlags may be OPEN_MODE_READ ,OPEN_MODE_WRITE ,OPEN_MODE_READWRITE
3. 检测文件是否存在:
函数 : INT CDataFile::CheckFileExsist(LPCTSTR lpszFileName)
方法 : 返回值可能是FLAG_FILE_EXIST,FLAG_FILE_NOEXIST
4. 获得文件的行数:
函数 : UINT CDataFile::GetLines()
方法 : 返回值为行数.
5. 将指针移动到你所要操作的行:
函数 : BOOL CDataFile::MoveToLine(UINT line)
方法 : 如果你想使用ReadLine()或WriteLine(),你必须首先使用MoveToLine().
6. 读取你要移动的行:
函数: BOOL CDataFile::ReadLine(CString &rString)
7. 在当前行插入,重写,删除一行:
函数 :void CDataFile::WriteLine(CString &wString, UINT nFlag)
说明 : nFlag可以是WRITE_MODE_INSERT ,WRITE_MODE_OVERWRITE 或者 WRITE_MODE_DELETE.如果nFlag是WRITE_MODE_DELETE,wString就是你所要删除的行的内容.
8. 关闭文件:
函数 : void CDataFile::CloseFile()
来源: http://www.codeguru.com/mfc_database/CDataFile.html |