共用方式為


fclose、_fcloseall

關閉資料流 (fclose) 或已經關閉所有開啟的資料流 (_fcloseall)。

int fclose( 
   FILE *stream 
);
int _fcloseall( void );

參數

  • stream
    指向 FILE 結構的指標。

傳回值

資料流,則成功關閉,則fclose 會傳回 0。 _fcloseall 會關閉資料流總數。 兩個函式表示錯誤的傳回 EOF 。

備註

fclose 函式會關閉 stream。 如果 stream 是 NULL,則叫用無效參數處理常式,如 參數驗證 中所述。 如果允許繼續執行, fclose 會設定 errno 為 EINVAL 並回傳 EOF 。 建議 stream 指標在呼叫這個函式一律先進行檢查。

如需更多關於這些和其他回傳碼的資訊,請參閱 _doserrno 、 errno 、 _sys_errlist 和 _sys_nerr (_doserrno, errno, _sys_errlist, and _sys_nerr)

_fcloseall 函式會關閉所有除了 stdin, stdout, stderr (而且, MS-DOS 中, _stdaux 和 _stdprn) 中開啟的資料流。 它也會關閉並刪除 tmpfile建立的所有暫存檔案。 在兩個函式,所有緩衝區與資料流關閉之前清除。 系統配置緩衝區,在資料流關閉時,釋放。 不會自動釋放由使用者的緩衝區具有指定 setbuf 的 setvbuf 。

Note: ,當這些函式來關閉資料流時,基礎檔案描述項和作業系統檔案控制代碼 (或) 關閉通訊端,以及資料流。 因此,在中,如果檔案初次開啟為檔案控制代碼或檔案描述項和關閉 fclose,也不要呼叫 _close 關閉檔案描述;不要呼叫 Win32 函式 CloseHandle 關閉檔案控制代碼。

fclose 和 _fcloseall 以防止所包含的程式碼受到干擾防止其他執行緒。 如需非鎖定的fclose版本,請參閱_fclose_nolock 。

需求

功能

必要的標頭

fclose

<stdio.h>

_fcloseall

<stdio.h>

如需其他相容性資訊,請參閱<簡介>中的相容性

範例

請參閱 fopen 的範例。

.NET Framework 對等用法

請參閱

參考

資料流 I/O

_close

_fdopen、_wfdopen

fflush

fopen、_wfopen

freopen、_wfreopen