本文介绍了如何创建自己的ostream / streambuf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 为了教育目的,我想创建一个ostream和流缓冲区来执行:For educational purposes I want to create a ostream and stream buffer to do: 在执行< myVar; 存储在deque容器中,而不是使用std:cout或写入文件 记录额外的数据, ;<我做了多少次.write,写入的字节数以及flush()的次数。但我不需要所有的信息。我尝试重载但失败可怕。我尝试过重写I tried overloading but failed horribly. I tried overloading write by doingostream& write( const char* s, streamsize n ) http:// www。 cplusplus.com/reference/iostream/ostream ),但是我还需要什么呢?in my basic_stringstream2 class (I copied paste basic_stringstream into my cpp file and modified it) but the code kept using basic_ostream. I looked through code and it looks like I need to overload xsputn (which isn't mention on this page http://www.cplusplus.com/reference/iostream/ostream ) but what else do I need to overload? and how do I construct my class (what does it need to inherit, etc)?推荐答案规范化的方法包括定义你的自己的streambuf。 您应该看看:The canonical approach consists in defining your own streambuf.You should have a look at: Angelika LAnger的文章在IOStreams派生 James Kanze对过滤streambuf的文章 boost.iostream 的应用程序示例Angelika LAnger's articles on IOStreams derivationJames Kanze's articles on filtering streambufsboost.iostream for examples of application 这篇关于如何创建自己的ostream / streambuf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-11 06:45