📅  最后修改于: 2020-09-25 08:37:35             🧑  作者: Mango
当文件被程序关闭(通过执行fclose)或程序终止时,该文件将被自动删除。
FILE* tmpfile();
它在
没有
#include
#include
#include
using namespace std;
int main()
{
FILE *fp;
fp = tmpfile();
char writeToFile[50] = "Creating a temporary file";
if (fp==NULL)
{
perror("Error creating temporary file");
exit(1);
}
fputs(writeToFile,fp);
rewind(fp);
char readFromFile[50];
fgets(readFromFile, sizeof(readFromFile), fp);
cout << readFromFile;
fclose(fp);
return 0;
}
运行该程序时,输出为:
Creating a temporary file