Get IOS to use a pipe? (subclass it?)

A

Average_Joe

My apologies if this is a mundane question everyone has asked at some point. I
don't usually work with c/c++ so there are probably obvious things that I'm
missing..

I'd like to find an elegant way to connect a handle as returned from
the unix pipe() system call to an istream object.

Is there a way to mix FILE handles with iostream objects? Would I need to
create another class that inherits from istream in order to get the handle
from pipe() to be an ios object? (I'm only interested in the reader side)

Is there an example some place about doing this kind of thing? I have to
think it's been done dozens of times in dozens of different ways.

Jamie
 
V

Victor Bazarov

Average_Joe said:
My apologies if this is a mundane question everyone has asked at some point. I
don't usually work with c/c++ so there are probably obvious things that I'm
missing..

Pipes are not part of C++. You may be better off asking in a newsgroup
where they are on topic, like the newsgroup for your OS.
I'd like to find an elegant way to connect a handle as returned from
the unix pipe() system call to an istream object.

Is there a way to mix FILE handles with iostream objects?

There probably is, but it's usually not a good idea.
> Would I need to
create another class that inherits from istream in order to get the handle
from pipe() to be an ios object? (I'm only interested in the reader side)

I believe you'd be better off inheriting from streambuf. That class is
specifically designed to be inherited from.
Is there an example some place about doing this kind of thing? I have to
think it's been done dozens of times in dozens of different ways.

Yes, I bet there is. Where have you already looked? Google? Books?

V
 
J

John Harrison

Average_Joe said:
My apologies if this is a mundane question everyone has asked at some point. I
don't usually work with c/c++ so there are probably obvious things that I'm
missing..

I'd like to find an elegant way to connect a handle as returned from
the unix pipe() system call to an istream object.

Is there a way to mix FILE handles with iostream objects? Would I need to
create another class that inherits from istream in order to get the handle
from pipe() to be an ios object? (I'm only interested in the reader side)

Not istream, streambuf. You are right this question gets asked a lot,
and people usually assume that they need to derive from istream. But
istream and ostream only do formatting, the real I/O is done by
streambuf derived classes (e.g. filebuf for files, stringbuf for
strings). You need a class (called pipebuf say) that derives from streambuf.
Is there an example some place about doing this kind of thing? I have to
think it's been done dozens of times in dozens of different ways.

The internet, google for streambuf, I'm sure you'll find something.

John
 
P

P.J. Plauger

My apologies if this is a mundane question everyone has asked at some
point. I
don't usually work with c/c++ so there are probably obvious things that
I'm
missing..

I'd like to find an elegant way to connect a handle as returned from
the unix pipe() system call to an istream object.

Is there a way to mix FILE handles with iostream objects? Would I need to
create another class that inherits from istream in order to get the handle
from pipe() to be an ios object? (I'm only interested in the reader side)

Is there an example some place about doing this kind of thing? I have to
think it's been done dozens of times in dozens of different ways.

It was even in the draft C++ Standard for a while, but got cut. If you're
using VC++, or another compiler with the Dinkumware C++ library, you
can construct a filebuf with a FILE *, which you can in turn construct
from a file descriptor.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
 
A

Average_Joe

I believe you'd be better off inheriting from streambuf. That class is
specifically designed to be inherited from.


Yes, I bet there is. Where have you already looked? Google? Books?

Both, but I was searching on "iostream" and "pipes" (Not streambuf) Will
try streambuf and pipe() this time. Thanks for the tip. (Now I just have
to find some info on what/where "streambuf" is)

Regarding books and information about CPP, I see a LOT of tutorial sites
with examples on how to do things, I've got a few books on the topic too.
Problem is, there are so many resources it's hard to know which ones to
use.

Unfortunately, I've yet to find a good, electronic ebook of the standard
libraries. Something like javadoc or perldoc, (ideally in some format that can
be converted to a vim help file or texinfo, something that can be read using a
terminal instead of GUI)

I would have thought "C++ The Core Language" would have the reference,
it doesn't. :-/

Know of a good source for such a thing? http://www.dinkumware.com/ comes close,
but it's not quite what I had in mind.

Jamie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top