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

后端 未结 7 1296
北荒
北荒 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:26

    On Linux (starting with kernel 3.11), there's flag to open(2) O_TMPFILE that creates a temporary file that doesn't have a name (i.e. it doesn't show up in the filesystem). This has a few interesting features:

    • No worries about unique names, it's just an inode, there is no name.
    • No race conditions during creation (e.g. symlink attacks).
    • No stray files if your app crashes, it's always automatically deleted.
    0 讨论(0)
提交回复
热议问题