|
-
January 4th, 2008, 06:32 PM
#1
[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
Last edited by couling; January 11th, 2008 at 04:15 PM.
Reason: [Resolved]
-
January 4th, 2008, 10:24 PM
#2
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).
-
January 5th, 2008, 12:25 PM
#3
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.
-
January 5th, 2008, 12:47 PM
#4
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
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.
Last edited by couling; January 5th, 2008 at 12:49 PM.
-
January 11th, 2008, 05:28 PM
#5
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|