std::tmpfile
Da cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Definido no cabeçalho <cstdio>
|
||
FILE* tmpfile(); |
||
Cria e abre um arquivo temporário com nome gerado automaticamente única.
Original:
Creates and opens a temporary file with unique auto-generated filename.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
O arquivo é aberto como um arquivo binário para atualização (como por std::fopen com o modo de acesso
"wb+"
). Arquivos, pelo menos, TMP_MAX podem ser abertas durante a vigência de um programa (este limite pode ser compartilhada com std::tmpnam e pode ser ainda mais limitada por FOPEN_MAX)Original:
The file is opened as binary file for update (as by std::fopen with access mode
"wb+"
). At least TMP_MAX files may be opened during the lifetime of a program (this limit may be shared with std::tmpnam and may be further limited by FOPEN_MAX)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Se o programa é fechado o ficheiro, por exemplo, executando std::fclose, o arquivo é automaticamente excluído.
Original:
If the program closes the file, e.g. by executing std::fclose, the file is automatically deleted.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Se o programa termina normalmente (chamando std::exit, retornando de main, etc), todos os arquivos que foram abertos chamando
std::tmpfile
também são excluídos automaticamente.Original:
If the program terminates normally (by calling std::exit, returning from main, etc), all files that were opened by calling
std::tmpfile
are also automatically deleted.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Se o programa termina de forma anormal, é definida pela implementação se esses arquivos temporários são excluídos.
Original:
If the program terminates abnormally, it is implementation-defined if these temporary files are deleted.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Índice |
[editar] Parâmetros
(Nenhum)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[editar] Valor de retorno
O fluxo de arquivo associado ou NULL se um erro ocorreu
Original:
The associated file stream or NULL if an error has occurred
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[editar] Notas
Em algumas implementações (por exemplo, Linux), esta função realmente cria, abre, e imediatamente exclui o arquivo do sistema de arquivos: enquanto um descritor de arquivo aberto com um arquivo excluído é realizada por um programa, o arquivo existe, mas desde que foi excluído, seu nome não aparece em qualquer diretório, para que nenhum outro processo pode abri-lo. Uma vez que o descritor de arquivo é fechado, o espaço ocupado pelo arquivo é recuperado pelo sistema de arquivos.
Original:
On some implementations (e.g. Linux), this function actually creates, opens, and immediately deletes the file from the file system: as long as an open file descriptor to a deleted file is held by a program, the file exists, but since it was deleted, its name does not appear in any directory, so that no other process can open it. Once the file descriptor is closed, the space occupied by the file is reclaimed by the filesystem.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[editar] Exemplo
#include <iostream> #include <cstdio> #include <cstdlib> int main() { FILE* tmpf = std::tmpfile(); std::fputs("Hello, world", tmpf); std::rewind(tmpf); char buf[6]; std::fgets(buf, sizeof buf, tmpf); std::cout << buf << '\n'; // Linux-specific method to display the tmpfile name std::system("ls -l /proc/self/fd/3"); }
Potencial saída:
Hello lrwx------ 1 user group 64 Jun 27 00:28 /proc/self/fd/3 -> /tmp/tmpfXu58Zi (deleted)
[editar] Veja também
retorna um nome único Original: returns a unique filename The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função) | |
Documentação C para tmpfile
|