请问:关于临时文件?

yhang_wang 2002-03-30 06:58:24
我想做一个临时文件作为已有文件的替代,要求这个文件对用户始终是不可见的。我开始时生成一个新文件,用拷贝的方法,但是如果我的程序非正常退出的话,那这个文件不能删除。我记得jeffrey的书上好像有似的,但像不起了。
请教各位大哥一下,有没有比较简便易行的方案?谢谢!
...全文
105 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
yhang_wang 2002-03-30
  • 打赏
  • 举报
回复
error0,谢谢。我想起如何做来了。

给分。

也谢谢大家关心。
yhang_wang 2002-03-30
  • 打赏
  • 举报
回复
其实那只是内存中的东东,只是已“文件”的形式呈现给大家。

我是不知道怎么做了。

有没有其他的又创意的想法?
error0 2002-03-30
  • 打赏
  • 举报
回复
MFC Library Reference

CMemFile Class





class CMemFile : public CFile
Remarks
CMemFile is the CFile-derived class that supports memory files. These memory files behave like disk files except that the file is stored in RAM rather than on disk. A memory file is useful for fast temporary storage or for transferring raw bytes or serialized objects between independent processes.

CMemFile objects can automatically allocate their own memory or you can attach your own memory block to the CMemFile object by calling Attach. In either case, memory for growing the memory file automatically is allocated in nGrowBytes-sized increments if nGrowBytes is not zero.

The memory block will automatically be deleted upon destruction of the CMemFile object if the memory was originally allocated by the CMemFile object; otherwise, you are responsible for deallocating the memory you attached to the object.

You can access the memory block through the pointer supplied when you detach it from the CMemFile object by calling Detach.

The most common use of CMemFile is to create a CMemFile object and use it by calling CFile member functions. Note that creating a CMemFile automatically opens it: you do not call CFile::Open, which is only used for disk files. Because CMemFile doesn't use a disk file, the data member CFile::m_hFile is not used and has no meaning.

The CFile member functions Duplicate, LockRange, and UnlockRange are not implemented for CMemFile. If you call these functions on a CMemFile object, you will get a CNotSupportedException.

CMemFile uses the run-time library functions malloc, realloc, and free to allocate, reallocate, and deallocate memory; and the intrinsic memcpy to block copy memory when reading and writing. If you'd like to change this behavior or the behavior when CMemFile grows a file, derive your own class from CMemFile and override the appropriate functions.

For more information on CMemFile, see the articles Files in MFC and Memory Management (MFC) and see File Handling in the Run-Time Library Reference.

Requirements
Header: afx.h

yhang_wang 2002-03-30
  • 打赏
  • 举报
回复
哦,你知道有一种临时文件,其实是系统替你维护的,当你的进程不管什么原因结束时,都会被自动删除掉。我知道肯定可以实现的,就是找不到方法了。

这样,我可以生成一个临时文件,但当我向里面拷贝内容的时候出错。现在问题可能在与:怎样网一个临时文件中拷贝已经存在文件的内容?
ahao 2002-03-30
  • 打赏
  • 举报
回复
我不明白你的意思,在内存里的,那和临时文件有什么关系?
yhang_wang 2002-03-30
  • 打赏
  • 举报
回复
ahao(天·狼·星星)

对,是的,我是像这样做的,我就是不知道内存临时文件该怎么做,请执教?
ahao 2002-03-30
  • 打赏
  • 举报
回复
那绝对只能放在内存里并加密
yhang_wang 2002-03-30
  • 打赏
  • 举报
回复
involute(哼哼唧唧) :
问题是那样的话,我的一些重要信息就会以明文形式出现在那里,很危险。所以我必须保证其时间上空间上的独立性与保密性。
yhang_wang 2002-03-30
  • 打赏
  • 举报
回复
是这样,你说的那些不是我想要的。 问题是如何生成临时文件让他具有已经存在文件的内容:注意!临时文件是肯定要被删除的。
谢谢老兄关心!
involute 2002-03-30
  • 打赏
  • 举报
回复
非正常退出还删除什么临时文件啊?干脆把它放到Windows的临时文件文件夹中,不要放在当前目录,这样用户在当前目录就看不到你的临时文件了!
zhuyj 2002-03-30
  • 打赏
  • 举报
回复
这个我也不清楚,但是我觉得,可以让程序启动的时候在检查一下临时文件是否存在,若存在,则删除它,然后新建

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧