howto inherit from ostream/istream 
Author Message
 howto inherit from ostream/istream

Hi,

I want to create a wrapper class for pipe communication between programs.
How can I do it so that I get all the funtionality of the iostreams, like
<<, >>, getline, etc. Is this documented somewhere? My C++ book doesn't
describe this.
Thanks!

--

Daniel Lidstr?m

62 23' 25" N
17 15' 31" E



Sun, 10 Apr 2005 05:09:29 GMT  
 howto inherit from ostream/istream
The book "Standard C++ IOStreams and Locales" written by Angelika Langer and
Klaus Kreft discusses how to extend or define new stream classes.


Quote:
> Hi,

> I want to create a wrapper class for pipe communication between programs.
> How can I do it so that I get all the funtionality of the iostreams, like
> <<, >>, getline, etc. Is this documented somewhere? My C++ book doesn't
> describe this.
> Thanks!

> --

> Daniel Lidstr?m

> 62 23' 25" N
> 17 15' 31" E



Sun, 10 Apr 2005 08:39:25 GMT  
 howto inherit from ostream/istream
On Tue, 22 Oct 2002 23:09:29 +0200, "Daniel Lidstr?m"

Quote:

>Hi,

>I want to create a wrapper class for pipe communication between programs.
>How can I do it so that I get all the funtionality of the iostreams, like
><<, >>, getline, etc. Is this documented somewhere? My C++ book doesn't
>describe this.

You need to derive from std::streambuf. If you can get your pipe into
a FILE*, you may not need to; Dinkumware's std::filebuf has a
constructor that takes a FILE*, as an extension to standard C++.

Tom



Sun, 10 Apr 2005 16:51:08 GMT  
 howto inherit from ostream/istream

Quote:
> I want to create a wrapper class for pipe communication between programs.
> How can I do it so that I get all the funtionality of the iostreams, like
> <<, >>, getline, etc. Is this documented somewhere? My C++ book doesn't
> describe this.

Maybe you don't need derivation at all.  Check the following code which
allows an imaginary pipe object to be passed to a ostream class:

class pipe
{
 public:
  void read_pipe(std::string & str) const
  {
   // fill in str from the pipe
  }

Quote:
};

inline std::ostream & operator << (std::ostream & os, pipe const & p)
{
  std::string str;
  p.read_pipe( str );
  return os << str;

Quote:
}

// the client code:
pipe p;
std::cout << p;

Does this help?
--

Ehsan Akhgari



[WWW: http://www.beginthread.com/Ehsan ]



Sun, 10 Apr 2005 18:43:19 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. istream, ostream, we all scream!

2. istream, ostream, we all scream!

3. CEdit subclass as istream and ostream?

4. istream/ostream and empty string

5. std::ostream vs ostream

6. std::ostream vs ostream (microsoft) and DLLs and BUG?!

7. Rounding error in C printf / C++ ostream on UNIX platforms

8. ostream derived class does not print

9. derive from ostream

10. OSTREAM

11. ostream dll bug?

12. ostream overloading

 

 
Powered by phpBB® Forum Software