This wrapper class implements just that.
You get an intuitive interface to files with easy-to-remember access methods like Open()
and Create()
. And of course the destructor will close the file, so
you don't need to remember to call Close()
.
The following code sample should give you an idea about how it is used:
CFile f;
if( f.Open(szFilename)==TRUE ) {
FILETIME ftModified;
f.GetFileTime(NULL, NULL, &ftModified);
DWORD dwSize = f.GetSize();
LPSTR pBuffer = (LPSTR) new CHAR[dwSize + 1];
f.Read(pBuffer, dwSize);
pBuffer[dwSize] = '\0';
f.Close();
...
delete [] pBuffer;
}
Interface
Name | Description | |
---|---|---|
![]() | Create | Creates a new file |
![]() | Open | Opens an existing file. |
![]() | Close | Closes the file. |
![]() | Read | Reads a number of bytes from the file. |
![]() | Write | Writes a number of bytes to the file. |
![]() | Seek | Sets the file position. |
![]() | GetPosition | Returns the current file position. |
![]() | Flush | Flushes all uncommitted data to the file. |
![]() | DuplicateHandle | Duplicate file handle. |
![]() | GetSize | Returns the size of the file. |
![]() | GetFileTime | Returns the file creation-, modification- and access-times. |
![]() | FileExists | Returns whether a filename exists. |
![]() | Delete | Deletes a file. |
![]() | Rename | Renames a file. |
Source Code Dependencies
Microsoft ATL LibraryDownload Files
![]() | Source Code (3 Kb) |