从std :: ofstream获取一个HANDLE [英] Getting a HANDLE from a std::ofstream

查看:260
本文介绍了从std :: ofstream获取一个HANDLE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从std :: ofstream(Visual C ++ 2005)获取底层文件HANDLE?

Is it possible to get the underlying file HANDLE from a std::ofstream (Visual C++ 2005)?

这与这个问题相反:

我可以使用CreateFile,但强制该句柄为std :: ofstream?

我想这样做的原因是修改属性

The reason I want to so this is to modify attributes of the file (e.g. creation time) without having to open the file with CreateFile.

推荐答案

C ++标准没有提供任何用于指定文件的方法或检索 ofstream 的原始文件描述符,因此我不相信这是可能的。 可能是建立一个自定义的 streambuf 类来实现流缓冲到 HANDLE ,然后定义使用该缓冲区的自定义 ostream 类型。我不知道这是否真的是你想要的,但它是一个可行的选择。

The C++ standard does not provide any means for specifying or retrieving the raw file descriptors of an ofstream, so I don't believe this is possible. What is possible, though, would be to build a custom streambuf class that implements stream buffering to and from a HANDLE, then to define a custom ostream type that uses that buffer. I'm not sure if that's really what you're looking for, but it is a viable option.

这篇关于从std :: ofstream获取一个HANDLE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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