从stdio文件构造流 [英] Construct ofstream from stdio file
本文介绍了从stdio文件构造流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从给定的stdio文件(旧式C文件句柄)创建一个ofstream对象?最好不要关闭并重新打开文件。
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.
这样做的目的是我有一个stdio文件和一个我正在使用的库获取一个流对象。
The purpose for this is I have a stdio file and a library I'm using takes a stream object.
推荐答案
如果使用boost是一个选项,并且库需要 std :: basic_ostream
(而不是 std :: ofstream
)你可以使用文件描述符接收器来包装你的文件描述符,构造一个 stream ,并将其传递给目标库。
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.
这篇关于从stdio文件构造流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文