我该如何从标准流派生自己的流?
C#语言中有Stream类,但C++的流太复杂了。
我想要像这样的东西:
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);
}
注意:这段代码只是一个示例,可能不是有效的C++程序。 谢谢。