tmpfile

建立暫存檔。此函式是取代,因為更安全的版本是可使用; see tmpfile_s.

FILE *tmpfile( void );

傳回值

如果成功的話, tmpfile傳回的資料流指標。否則,它會傳回NULL指標。

備註

tmpfile函式會建立暫存檔,並傳回該資料流的指標。 根中建立暫存檔。若要建立的暫存檔中根以外的目錄,請使用 tmpnamtempnamfopen

如果無法開啟檔案, tmpfile會傳回NULL指標。 檔案關閉時,一般情況下,或當,結束程式時,會自動刪除這個暫存檔_rmtmp呼叫時,假設目前的工作目錄並不會變更。在開啟暫存檔案w+b (二進位讀取/寫入) 模式。

如果您嘗試使用超過 TMP_MAX,就會發生失敗 (請參閱 STDIO。H) 呼叫tmpfile。

需求

常式

所需的標題

tmpfile

<stdio.h>

其他的相容性資訊,請參閱相容性在簡介中。

範例

注意事項注意事項

您必須擁有系統管理員權限,才能在 Windows Vista 中執行本範例。

// crt_tmpfile.c
// compile with: /W3
// This program uses tmpfile to create a
// temporary file, then deletes this file with _rmtmp.
#include <stdio.h>

int main( void )
{
   FILE *stream;
   int  i;

   // Create temporary files.
   for( i = 1; i <= 3; i++ )
   {
      if( (stream = tmpfile()) == NULL ) // C4996
      // Note: tmpfile is deprecated; consider using tmpfile_s instead
         perror( "Could not open new temporary file\n" );
      else
         printf( "Temporary file %d was created\n", i );
   }

   // Remove temporary files.
   printf( "%d temporary files deleted\n", _rmtmp() );
}
  

.NET Framework 對等用法

不適用。 若要呼叫標準的 c函式,請使用PInvoke。 如需詳細資訊,請參閱平台叫用範例

請參閱

參考

資料流 I/O

_rmtmp

_tempnam、 _wtempnam、 tmpnam、 _wtmpnam