tmpfiletmpfile
Создает временный файл.Creates a temporary file. Эта функция устарела, так как появилась более безопасная версия; см. раздел tmpfile_s.This function is deprecated because a more secure version is available; see tmpfile_s.
СинтаксисSyntax
FILE *tmpfile( void );
Возвращаемое значениеReturn Value
В случае успеха tmpfile возвращает указатель потока.If successful, tmpfile returns a stream pointer. В противном случае возвращается пустой указатель.Otherwise, it returns a NULL pointer.
КомментарииRemarks
Функция tmpfile создает временный файл и возвращает указатель на этот поток.The tmpfile function creates a temporary file and returns a pointer to that stream. Временный файл создается в корневом каталоге.The temporary file is created in the root directory. Чтобы создать временный файл в каталоге, отличном от корневого, используйте tmpnam_s или tempnam в сочетании с fopen.To create a temporary file in a directory other than the root, use tmpnam or tempnam in conjunction with fopen.
Если не удается открыть файл, tmpfile возвращает пустой указатель.If the file cannot be opened, tmpfile returns a NULL pointer. Этот временный файл автоматически удаляется при закрытии файла, при завершении программы в обычном режиме или при вызове _rmtmp , предполагая, что текущий рабочий каталог не изменяется.This temporary file is automatically deleted when the file is closed, when the program terminates normally, or when _rmtmp is called, assuming that the current working directory does not change. Временный файл открывается в режиме w + b (двоичный для чтения и записи).The temporary file is opened in w+b (binary read/write) mode.
Сбой может произойти при попытке более TMP_MAX (см. STDIO. H) вызывает метод с tmpfile.Failure can occur if you attempt more than TMP_MAX (see STDIO.H) calls with tmpfile.
ТребованияRequirements
ПодпрограммаRoutine | Обязательный заголовокRequired header |
---|---|
tmpfiletmpfile | <stdio.h> |
Дополнительные сведения о совместимости см. в статье Compatibility.For additional compatibility information, see Compatibility.
ПримерExample
Примечание
В этом примере требуются права администратора для работы в Windows Vista.This example requires administrative privileges to run on 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() );
}
Temporary file 1 was created
Temporary file 2 was created
Temporary file 3 was created
3 temporary files deleted
См. также разделSee also
Потоковый ввод-выводStream I/O
_rmtmp_rmtmp
_tempnam, _wtempnam, tmpnam, _wtmpnam_tempnam, _wtempnam, tmpnam, _wtmpnam