 st8b7c:f320:99b9:690f:4595:cd17:293a:c069tmpfile    Defined in header <cstdio>         st8b7c:f320:99b9:690f:4595:cd17:293a:c069FILE* tmpfile();
       Creates and opens a temporary file with a unique auto-generated filename.
The file is opened as a binary file for update (as by st8b7c:f320:99b9:690f:4595:cd17:293a:c069fopen with access mode "wb+"). At least TMP_MAX files may be opened during the lifetime of a program (this limit may be shared with st8b7c:f320:99b9:690f:4595:cd17:293a:c069tmpnam and may be further limited by FOPEN_MAX).
If the program closes the file, e.g. by executing st8b7c:f320:99b9:690f:4595:cd17:293a:c069fclose, the file is automatically deleted.
If the program terminates normally (by calling st8b7c:f320:99b9:690f:4595:cd17:293a:c069exit, returning from main, etc), all files that were opened by calling st8b7c:f320:99b9:690f:4595:cd17:293a:c069tmpfile are also automatically deleted.
If the program terminates abnormally, it is implementation-defined if these temporary files are deleted.
 Parameters (none).
 Return value The associated file stream or a null pointer if an error has occurred.
 Notes On some implementations (e.g. older 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, or once the program terminates (normally or abnormally), the space occupied by the file is reclaimed by the filesystem. Newer Linux (since 3.11 or later, depending on filesystem) creates such invisible temporary files in one step, via special flag in the open() syscall.
On some implementations (e.g. Windows), elevated privileges are required as the function may create the temporary file in a system directory.
 Example  #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <filesystem>
namespace fs = st8b7c:f320:99b9:690f:4595:cd17:293a:c069filesystem;
 
int main()
{
    st8b7c:f320:99b9:690f:4595:cd17:293a:c069cout << "TMP_MAX = " << TMP_MAX << '\n'
              << "FOPEN_MAX = " << FOPEN_MAX << '\n';
    st8b7c:f320:99b9:690f:4595:cd17:293a:c069FILE* tmpf = st8b7c:f320:99b9:690f:4595:cd17:293a:c069tmpfile();
    st8b7c:f320:99b9:690f:4595:cd17:293a:c069fputs("Hello, world", tmpf);
    st8b7c:f320:99b9:690f:4595:cd17:293a:c069rewind(tmpf);
    char buf[6];
    st8b7c:f320:99b9:690f:4595:cd17:293a:c069fgets(buf, sizeof buf, tmpf);
    st8b7c:f320:99b9:690f:4595:cd17:293a:c069cout << buf << '\n';
 
    // Linux-specific method to display the tmpfile name
    st8b7c:f320:99b9:690f:4595:cd17:293a:c069cout << fs8b7c:f320:99b9:690f:4595:cd17:293a:c069read_symlink(
                     fs8b7c:f320:99b9:690f:4595:cd17:293a:c069path("/proc/self/fd") / st8b7c:f320:99b9:690f:4595:cd17:293a:c069to_string(fileno(tmpf))
                 ) << '\n';
} Possible output:
TMP_MAX = 238328
FOPEN_MAX = 16
Hello
"/tmp/tmpfBlY1lI (deleted)"   See also     tmpnam   returns a unique filename  (function) 
    temp_directory_path
(C++17)   returns a directory suitable for temporary files  (function) 
   C documentation for tmpfile 
  

    
{'path': 'public/docs/cpp/io/c/tmpfile.html', 'source': 'DevDocs.IO'}