How to create a temporary text file in C++?

后端 未结 7 1317
北荒
北荒 2020-12-09 08:30

I\'m trying to create a temporary text file in C++ and then delete it at the end of the program. I haven\'t had much luck with Google.

Could you tell me which funct

7条回答
  •  星月不相逢
    2020-12-09 09:03

    Maybe this will help

    FILE * tmpfile ( void );
    

    http://www.cplusplus.com/reference/clibrary/cstdio/tmpfile/

    Open a temporary file

    Creates a temporary binary file, open for update (wb+ mode -- see fopen for details). The filename is guaranteed to be different from any other existing file. The temporary file created is automatically deleted when the stream is closed (fclose) or when the program terminates normally.

    See also

    char * tmpnam ( char * str );
    

    Generate temporary filename

    A string containing a filename different from any existing file is generated. This string can be used to create a temporary file without overwriting any other existing file.

    http://www.cplusplus.com/reference/clibrary/cstdio/tmpnam/

提交回复
热议问题