简体   繁体   English

如何为fstream对象设置标志FILE_FLAG_BACKUP_SEMANTICS?

[英]How can I set the flag FILE_FLAG_BACKUP_SEMANTICS for an fstream object?

How can I set the flag FILE_FLAG_BACKUP_SEMANTICS for an fstream object? 如何为fstream对象设置标志FILE_FLAG_BACKUP_SEMANTICS?

You can set most flags with fstream, but it seems like this one is not availble. 您可以使用fstream设置大多数标志,但似乎这不可用。 You can read about the flag here . 您可以在此处阅读有关该标志的信息

I've done this sort thing in the past but it's been a while so I'm not sure I have it right. 我过去做过这类事情,但是已经有一段时间了,所以我不确定我是否正确。

Not well documented, but in vs2008, fstream takes a FILE object as a constructor. 没有充分的文档说明,但是在vs2008中,fstream将FILE对象用作构造函数。 You can create a FILE object from a file id with _fdopen(). 您可以使用_fdopen()从文件ID创建FILE对象。 You can get a file id from an os handle using _open_osfhandle. 您可以使用_open_osfhandle从os句柄获取文件ID。

So I think it's like: 所以我认为这就像:

int id = _open_osfhandle(CreateFile(..., FILE_FLAG_BACKUP_SEMANTICS...));
fstream f = new fstream(_fdopen(id));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM