How can I derive my own stream from a standard stream?
问题 How can I derive my own stream from a standard stream? In C# language, there is a Stream class, but C++'s streams are too complex. I want something like this: class my_stream : public std::stream { // How to derive? }; void using_a_stream(std::stream* s) { *s << "Hello world"; } void main() { std::stream s1; std::fstream s2("C:\\test.txt"); my_stream s3; using_a_stream(&s1); using_a_stream(&s2); using_a_stream(&s3); } Note: The code just a sample and may be invalid C++ program. Thanks. 回答1: I