Construct ofstream from stdio file

陌路散爱 提交于 2019-12-10 17:24:54

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8073846/construct-ofstream-from-stdio-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!