Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a HANDLE from a std::ofstream

Tags:

c++

winapi

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

This is the opposite of this question:

Can I use CreateFile, but force the handle into a 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.

like image 880
mpipe3 Avatar asked Feb 04 '11 08:02

mpipe3


1 Answers

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.

like image 135
templatetypedef Avatar answered Nov 14 '22 22:11

templatetypedef