Getting a HANDLE from a std::ofstream

后端 未结 6 1713
天涯浪人
天涯浪人 2021-01-18 14:34

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 for

6条回答
  •  一生所求
    2021-01-18 15:10

    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.

提交回复
热议问题