You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/mfc/reference/cfile-class.md
+35-35Lines changed: 35 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -76,7 +76,7 @@ It directly provides unbuffered, binary disk input/output services, and it indir
76
76
77
77
The hierarchical relationship between this class and its derived classes allows your program to operate on all file objects through the polymorphic `CFile` interface. A memory file, for example, behaves like a disk file.
78
78
79
-
Use `CFile` and its derived classes for general-purpose disk I/O. Use `ofstream` or other Microsoft iostream classes for formatted text sent to a disk file.
79
+
Use `CFile` and its derived classes for general-purpose disk I/O. Use `ofstream` or other Microsoft `iostream` classes for formatted text sent to a disk file.
80
80
81
81
Normally, a disk file is opened automatically on `CFile` construction and closed on destruction. Static member functions permit you to interrogate a file's status without opening the file.
82
82
@@ -102,9 +102,9 @@ virtual void Abort();
102
102
103
103
### Remarks
104
104
105
-
If you have not closed the file before destroying the object, the destructor closes it for you.
105
+
If you haven't closed the file before destroying the object, the destructor closes it for you.
106
106
107
-
When handling exceptions, `CFile::Abort` differs from `CFile::Close` in two important ways. First, the `Abort` function will not throw an exception on failures because failures are ignored by `Abort`. Second, `Abort`will not **ASSERT** if the file has not been opened or was closed previously.
107
+
When handling exceptions, `CFile::Abort` differs from `CFile::Close` in two important ways. First, the `Abort` function won't throw an exception on failures, because failures are ignored by `Abort`. Second, `Abort`won't **ASSERT** if the file hasn't been opened, or was closed previously.
108
108
109
109
If you used **new** to allocate the `CFile` object on the heap, then you must delete it after closing the file. `Abort` sets `m_hFile` to `CFile::hFileNull`.
110
110
@@ -178,31 +178,31 @@ Choose the first, or both, of the following file creation mode options. The defa
178
178
179
179
|Value|Description|
180
180
|-----------|-----------------|
181
-
|`CFile::modeCreate`|Creates a new file if no file exists. If the file already exists, it is overwritten and initially set to zero length.|
182
-
|`CFile::modeNoTruncate`|Creates a new file if no file exists; otherwise, if the file already exists, it is attached to the `CFile` object.|
181
+
|`CFile::modeCreate`|Creates a new file if no file exists. If the file already exists, it's overwritten and initially set to zero length.|
182
+
|`CFile::modeNoTruncate`|Creates a new file if no file exists; otherwise, if the file already exists, it's attached to the `CFile` object.|
183
183
184
-
Choose the following file caching options as described. By default, the system uses a generalpurpose caching scheme that is not available as an option.
184
+
Choose the following file caching options as described. By default, the system uses a general-purpose caching scheme that isn't available as an option.
185
185
186
186
|Value|Description|
187
187
|-----------|-----------------|
188
-
|`CFile::osNoBuffer`|The system does not use an intermediate cache for the file. This option cancels the following 2 options.|
189
-
|`CFile::osRandomAccess`|The file cache is optimized for random access. Do not use this option and the sequential scan option.|
190
-
|`CFile::osSequentialScan`|The file cache is optimized for sequential access. Do not use this option and the random access option.|
191
-
|`CFile::osWriteThrough`|Write operations are performed without delay.|
188
+
|`CFile::osNoBuffer`|The system doesn't use an intermediate cache for the file. This option cancels the following 2 options.|
189
+
|`CFile::osRandomAccess`|The file cache is optimized for random access. Don't use both this option and the sequential scan option.|
190
+
|`CFile::osSequentialScan`|The file cache is optimized for sequential access. Don't use both this option and the random access option.|
191
+
|`CFile::osWriteThrough`|Write operations are done without delay.|
192
192
193
193
Choose the following security option to prevent the file handle from being inherited. By default, any new child processes can use the file handle.
194
194
195
195
|Value|Description|
196
196
|-----------|-----------------|
197
197
|`CFile::modeNoInherit`|Prevents any child processes from using the file handle.|
198
198
199
-
The default constructor initializes members but does not attach a file to the `CFile` object. After using this constructor, use the [CFile::Open](#open) method to open a file and attach it to the `CFile` object.
199
+
The default constructor initializes members but doesn't attach a file to the `CFile` object. After using this constructor, use the [CFile::Open](#open) method to open a file and attach it to the `CFile` object.
200
200
201
201
The constructor with one parameter initializes members and attaches an existing file to the `CFile` object.
202
202
203
203
The constructor with two parameters initializes members and tries to open the specified file. If this constructor successfully opens the specified file, the file is attached to the `CFile` object; otherwise, this constructor throws a pointer to a `CInvalidArgException` object. For more information about how to handle exceptions, see [Exceptions](../../mfc/exception-handling-in-mfc.md).
204
204
205
-
If a `CFile` object successfully opens a specified file, it will close this file automatically when the `CFile` object is destroyed; otherwise, you must explicitly close the file after it is no longer attached to the `CFile` object.
205
+
If a `CFile` object successfully opens a specified file, it will close this file automatically when the `CFile` object is destroyed; otherwise, you must explicitly close the file after it's no longer attached to the `CFile` object.
206
206
207
207
### Example
208
208
@@ -220,7 +220,7 @@ virtual void Close();
220
220
221
221
### Remarks
222
222
223
-
If you have not closed the file before destroying the object, the destructor closes it for you.
223
+
If you haven't closed the file before destroying the object, the destructor closes it for you.
224
224
225
225
If you used **new** to allocate the `CFile` object on the heap, then you must delete it after closing the file. `Close` sets `m_hFile` to `CFile::hFileNull`.
226
226
@@ -242,7 +242,7 @@ A pointer to a duplicate `CFile` object.
242
242
243
243
### Remarks
244
244
245
-
This is equivalent to the C run-time function `_dup`.
245
+
This function is equivalent to the C run-time function `_dup`.
246
246
247
247
## <aname="flush"></a> CFile::Flush
248
248
@@ -254,7 +254,7 @@ virtual void Flush();
254
254
255
255
### Remarks
256
256
257
-
The use of `Flush`does not guarantee flushing of `CArchive` buffers. If you are using an archive, call [CArchive::Flush](../../mfc/reference/carchive-class.md#flush) first.
257
+
The use of `Flush`doesn't guarantee flushing of `CArchive` buffers. If you're using an archive, call [CArchive::Flush](../../mfc/reference/carchive-class.md#flush) first.
258
258
259
259
### Example
260
260
@@ -320,7 +320,7 @@ The title of the underlying file.
320
320
321
321
### Remarks
322
322
323
-
This method calls [GetFileTitle](/windows/desktop/api/commdlg/nf-commdlg-getfiletitlea) to retrieve the title of the file. If successful, the method returns the string that the system would use to display the file name to the user. Otherwise, the method calls [PathFindFileName](/windows/desktop/api/shlwapi/nf-shlwapi-pathfindfilenamea) to retrieve the file name (including the file extension) of the underlying file. Therefore, the file extension will not always be included in the returned file title string. For more information, see [GetFileTitle](/windows/desktop/api/commdlg/nf-commdlg-getfiletitlea) and [PathFindFileName](/windows/desktop/api/shlwapi/nf-shlwapi-pathfindfilenamea) in the Windows SDK.
323
+
This method calls [GetFileTitle](/windows/desktop/api/commdlg/nf-commdlg-getfiletitlea) to retrieve the title of the file. If successful, the method returns the string that the system would use to display the file name to the user. Otherwise, the method calls [PathFindFileName](/windows/desktop/api/shlwapi/nf-shlwapi-pathfindfilenamea) to retrieve the file name (including the file extension) of the underlying file. That means the file extension isn't always included in the returned file title string. For more information, see [GetFileTitle](/windows/desktop/api/commdlg/nf-commdlg-getfiletitlea) and [PathFindFileName](/windows/desktop/api/shlwapi/nf-shlwapi-pathfindfilenamea) in the Windows SDK.
324
324
325
325
To return the entire path of the file, including the name, call [GetFilePath](#getfilepath). To return just the name of the file, call [GetFileName](#getfilename).
326
326
@@ -346,7 +346,7 @@ The length of the file.
346
346
347
347
## <aname="getposition"></a> CFile::GetPosition
348
348
349
-
Obtains the current value of the file pointer, which can be used in subsequent calls to `Seek`.
349
+
Obtains the current value of the file pointer, which can be used in later calls to `Seek`.
350
350
351
351
```
352
352
virtual ULONGLONG GetPosition() const;
@@ -402,7 +402,7 @@ TRUE if the status information for the specified file is successfully obtained;
402
402
403
403
### Remarks
404
404
405
-
The non-static version of `GetStatus` retrieves status information of the open file associated with the given `CFile` object. The static version of `GetStatus` obtains the file status from a given file path without actually opening the file. This is useful for testing the existence and access rights of a file.
405
+
The non-static version of `GetStatus` retrieves status information of the open file associated with the given `CFile` object. The static version of `GetStatus` obtains the file status from a given file path without actually opening the file. This version is useful for testing the existence and access rights of a file.
406
406
407
407
The `m_attribute` member of the `CFileStatus` structure refers to the file attribute set. The `CFile` class provides the **Attribute** enumeration type so file attributes can be specified symbolically:
408
408
@@ -460,10 +460,10 @@ The number of bytes in the range to lock.
460
460
461
461
Locking bytes in a file prevents access to those bytes by other processes. You can lock more than one region of a file, but no overlapping regions are allowed.
462
462
463
-
When you unlock the region, using the `UnlockRange` member function, the byte range must correspond exactly to the region that was previously locked. The `LockRange` function does not merge adjacent regions; if two locked regions are adjacent, you must unlock each region separately.
463
+
When you unlock the region using the `UnlockRange` member function, the byte range must correspond exactly to the region that was previously locked. The `LockRange` function doesn't merge adjacent regions. If two locked regions are adjacent, you must unlock each region separately.
464
464
465
465
> [!NOTE]
466
-
> This function is not available for the `CMemFile`-derived class.
466
+
> This function isn't available for the `CMemFile`-derived class.
467
467
468
468
### Example
469
469
@@ -479,9 +479,9 @@ HANDLE m_hFile;
479
479
480
480
### Remarks
481
481
482
-
`m_hFile` is a public variable of type UINT. It contains `CFile::hFileNull` (an operating-system-independent empty file indicator) if the handle has not been assigned.
482
+
`m_hFile` is a public variable of type UINT. It contains `CFile::hFileNull`, an operating-system-independent empty file indicator, if the handle hasn't been assigned.
483
483
484
-
Use of `m_hFile`is not recommended because the member's meaning depends on the derived class. `m_hFile` is made a public member for convenience in supporting nonpolymorphic use of the class.
484
+
Use of `m_hFile`isn't recommended, because the member's meaning depends on the derived class. `m_hFile` is made a public member for convenience in supporting nonpolymorphic use of the class.
485
485
486
486
## <aname="m_ptm"></a> CFile::m_pTM
487
487
@@ -513,7 +513,7 @@ virtual BOOL Open(
513
513
### Parameters
514
514
515
515
*lpszFileName*<br/>
516
-
A string that is the path to the desired file. The path can be relative, absolute, or a network name (UNC).
516
+
A string that contains the path to the desired file. The path can be relative, absolute, or a network name (UNC).
517
517
518
518
*nOpenFlags*<br/>
519
519
A UINT that defines the file's sharing and access mode. It specifies the action to take when opening the file. You can combine options by using the bitwise-OR ( **|** ) operator. One access permission and one share option are required; the `modeCreate` and `modeNoInherit` modes are optional. See the [CFile](#cfile) constructor for a list of mode options.
@@ -530,9 +530,9 @@ Nonzero if the open was successful; otherwise 0. The *pError* parameter is meani
530
530
531
531
### Remarks
532
532
533
-
The two functions form a "safe" method for opening a file where a failure is a normal, expected condition.
533
+
The two `Open`functions are "safe" methods for opening a file, where a failure is a normal, expected condition.
534
534
535
-
While the `CFile` constructor will throw an exception in an error condition, `Open`will return FALSE for error conditions. `Open` can still initialize a [CFileException](../../mfc/reference/cfileexception-class.md) object to describe the error, however. If you don't supply the *pError* parameter, or if you pass NULL for *pError*, `Open`will return FALSE and not throw a `CFileException`. If you pass a pointer to an existing `CFileException`, and `Open` encounters an error, the function will fill it with information describing that error. In neither case will `Open` throw an exception.
535
+
While the `CFile` constructor throws an exception in an error condition, `Open`returns FALSE for error conditions. `Open` can still initialize a [CFileException](../../mfc/reference/cfileexception-class.md) object to describe the error, however. If you don't supply the *pError* parameter, or if you pass NULL for *pError*, `Open`returns FALSE and doesn't throw a `CFileException`. If you pass a pointer to an existing `CFileException`, and `Open` encounters an error, the function fills it with information describing that error. `Open`doesn't throw an exception in either case.
536
536
537
537
The following table describes the possible results of `Open`.
538
538
@@ -577,13 +577,13 @@ The maximum number of bytes to be read from the file. For text-mode files, carri
577
577
578
578
### Return Value
579
579
580
-
The number of bytes transferred to the buffer. Note that for all `CFile` classes, the return value may be less than *nCount* if the end of file was reached.
580
+
The number of bytes transferred to the buffer. For all `CFile` classes, the return value may be less than *nCount* if the end of file was reached.
@@ -605,9 +605,9 @@ Pointer to CAtlTransactionManager object
605
605
606
606
### Remarks
607
607
608
-
It will not remove a directory.
608
+
`Remove` won't remove a directory.
609
609
610
-
The `Remove` member function throws an exception if the connected file is open or if the file cannot be removed. This is equivalent to the DEL command.
610
+
The `Remove` member function throws an exception if the connected file is open or if the file can't be removed. This function is equivalent to the DEL command.
611
611
612
612
### Example
613
613
@@ -637,7 +637,7 @@ Pointer to CAtlTransactionManager object
637
637
638
638
### Remarks
639
639
640
-
Directories cannot be renamed. This is equivalent to the REN command.
640
+
Directories can't be renamed. This function is equivalent to the REN command.
641
641
642
642
### Example
643
643
@@ -677,7 +677,7 @@ The following table lists possible values for the *nFrom* parameter.
677
677
678
678
When a file is opened, the file pointer is positioned at 0, the start of the file.
679
679
680
-
You can set the file pointer to a position beyond the end of a file. If you do this, the size of the file does not increase until you write to the file.
680
+
You can set the file pointer to a position beyond the end of a file. If you do, the size of the file doesn't increase until you write to the file.
681
681
682
682
The exception handler for this method must delete the exception object after the exception is processed.
683
683
@@ -723,7 +723,7 @@ The length of the file in bytes.
723
723
724
724
## <aname="setfilepath"></a> CFile::SetFilePath
725
725
726
-
Call this function to specify the path of the file; for example, if the path of a file is not available when a [CFile](../../mfc/reference/cfile-class.md) object is constructed, call `SetFilePath` to provide it.
726
+
Call this function to specify the path of the file. For example, if the path of a file isn't available when a [CFile](../../mfc/reference/cfile-class.md) object is constructed, call `SetFilePath` to provide it.
727
727
728
728
```
729
729
virtual void SetFilePath(LPCTSTR lpszNewName);
@@ -782,7 +782,7 @@ static void PASCAL SetStatus(
782
782
A string that is the path to the desired file. The path can be relative or absolute, and can contain a network name.
783
783
784
784
*status*<br/>
785
-
The buffer containing the new status information. Call the `GetStatus` member function to prefill the `CFileStatus` structure with current values, then make changes as required. If a value is 0, then the corresponding status item is not updated. See the [GetStatus](#getstatus) member function for a description of the `CFileStatus` structure.
785
+
The buffer containing the new status information. Call the `GetStatus` member function to prefill the `CFileStatus` structure with current values, then make changes as required. If a value is 0, then the corresponding status item isn't updated. See the [GetStatus](#getstatus) member function for a description of the `CFileStatus` structure.
786
786
787
787
*pTM*<br/>
788
788
Pointer to CAtlTransactionManager object
@@ -791,7 +791,7 @@ Pointer to CAtlTransactionManager object
791
791
792
792
To set the time, modify the `m_mtime` field of *status*.
793
793
794
-
Please note that when you make a call to `SetStatus` in an attempt to change only the attributes of the file, and the `m_mtime` member of the file status structure is nonzero, the attributes may also be affected (changing the time stamp may have side effects on the attributes). If you want to only change the attributes of the file, first set the `m_mtime` member of the file status structure to zero and then make a call to `SetStatus`.
794
+
When you make a call to `SetStatus` in an attempt to change only the attributes of the file, and the `m_mtime` member of the file status structure is nonzero, the attributes may also be affected (changing the time stamp may have side effects on the attributes). If you want to only change the attributes of the file, first set the `m_mtime` member of the file status structure to zero and then make a call to `SetStatus`.
795
795
796
796
### Example
797
797
@@ -852,7 +852,7 @@ The number of bytes to be transferred from the buffer. For text-mode files, carr
0 commit comments