如何在C ++中创建临时文本文件? [英] How to create a temporary text file in C++?

查看:156
本文介绍了如何在C ++中创建临时文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在C ++中创建一个临时文本文件,然后删除它在程序的结束
。我没有多少运气与谷歌。

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 functions to use?

下面的答案告诉我如何创建一个临时文件。如果我只想
创建一个文件(tmp.txt)然后删除它呢?

The answers below tell me how to create a temp file. What if I just want to create a file (tmp.txt) and then delete it? How would I do that?

推荐答案

也许这会有帮助。

FILE * tmpfile ( void );

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


打开临时文件

Open a temporary file

创建一个临时二进制文件,打开
进行更新(wb +模式 - 详细信息请参阅fopen)。文件名保证
不同于任何其他
现有文件。当流关闭(fclose)或流程
正常终止时,
创建的临时文件
会自动删除。

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.

另请参阅

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/

这篇关于如何在C ++中创建临时文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆