[Resloved]How do you write you're own iostream?
Hi I'd like to make my own iostream class (for sockets).
I'm looking http://www.cplusplus.com/reference/ but it seems to be written more for those using streams than those writing them.
Dose anyone know where I can find an example of how do do this.
Thanks
Re: How do you write you're own iostream?
You could inherit a class from ios_base or ios, however you'll have to manually override the << operator for each type you want to be able to use.
If you want you could probably just write your own socket class that doesn't have to come from the stream libraries. Just override the << operator yourself and you should be good (I'm assuming that's why you want the stream capabilities).
Re: How do you write you're own iostream?
I'd suggest deriving one class from istream and another from ostream, just like ifstream and ofstream are.
Re: How do you write you're own iostream?
Yes. After searching for about a day, I've finally stumbled across this:
http://www.tacc.utexas.edu/services/...g/cre_2288.htm
Quote:
2.12.1 Choosing a base class
...
Choose basic_istream <charT,Traits>, basic_ostream <charT,Traits>, or basic_iostream <charT, Traits> as a base class when deriving new stream classes, unless you have good reason not to do so.
This allows you to make use of the existing << and >> operators for i/o/io-streams.
Edit: I should point out that istream is a typedef of the basic_istream template, the same follows for ostream and iostream.
This tutorial might tell me everything else I need to know. I'll mark this thread as resolved if it does.
Thanks for the advice guys.
Re: How do you write you're own iostream?
Just thought I'd give a pointer to anyone doing the same.
It seems that the iostream classes are a bit of a red herring .
They are really only a wrapper for the streambuf class. They provide parsing functionality etc. The actual IO is controlled by the streambuf class (using the protected virtual methods: underflow(), overflow() and sync()). So I've made my own streambuf class instead.
Once you've done this you can use a run-of-the-mill iostream object to provide you with a "custom iostream".
Thanks for your help guys.