Is it possible to create an ofstream object from a given stdio file (old-style C file handle)? Preferably without closing and re-opening the file.
The purpose for this is I have a stdio file and a library I'm using takes a stream object.
Is it possible to create an ofstream object from a given stdio file (old-style C file handle)? Preferably without closing and re-opening the file.
The purpose for this is I have a stdio file and a library I'm using takes a stream object.
If using boost is an option, and the library takes std::basic_ostream
(as opposed to an std::ofstream
) you could use a File Descriptor Sink to wrap your file descriptor, construct a stream from of it, and pass it to your target library.