473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
--
http://www.geniegate.com Custom web programming
User Management Solutions Perl / PHP / Java / UNIX

Sep 1 '05 #1
5 2592
Average_Joe wrote:
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.
Jamie


John
Sep 1 '05 #2
Average_Joe wrote:
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
Sep 1 '05 #3
"Average_Joe" <jo*@pong.tunestar.net> wrote in message
news:slrndherh4.vnf.jo*@pong.tunestar.net...
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
Sep 1 '05 #4
On 2005-09-01, Victor Bazarov <v.********@comAcast.net> wrote:
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?


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
--
http://www.geniegate.com Custom web programming
User Management Solutions Perl / PHP / Java / UNIX

Sep 2 '05 #5

Average_Joe wrote:

[]
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 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.


http://rsdn.ru/Forum/Message.aspx?mid=942482&only=1

Sep 2 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bernhard Kuemel | last post by:
Hi! I want to read/write commands and program input to/from /bin/bash several times before I close the stdin pipe. However, reading from cat hangs unless I first close the stdin pipe. <?php...
1
by: jenny | last post by:
Hi, I have a java socket program running on AIX 4.3.3.0 platform. It opens a socket and sends data to our customer over a leased fractional T1 line. The line is always connected. However,...
1
by: Gerry Sutton | last post by:
Hi All! I have noticed a strange behavior when using a constant identifier to initialize an instance list variable in a base class and then trying to modifying the list in subclasses by using...
5
by: richard | last post by:
I have a simple test to pass information from a client to a server using named pipe. what I really want is: when I type a line on the client, the server will output the line immediately. but to my...
7
by: Greg | last post by:
I am trying to implement the UNIX pipe command using C but with the "->" operator. Everything works fine with 1 pipe, but when I try to use 2 or more, it hangs up when reading the pipe_in...
2
by: FB's .NET Dev PC | last post by:
I am writing two services in VB.NET, one of which needs to send text strings to the other. After reading, I decided (perhaps incorrectly) that named pipes would be the best interprocess...
2
by: Steve R. Hastings | last post by:
While studying iterators and generator expressions, I started wishing I had some tools for processing the values. I wanted to be able to chain together a set of functions, sort of like the...
8
by: Lou Pecora | last post by:
I've been scanning Python in a Nutshell, but this seems to be either undoable or so subtle that I don't know how to do it. I want to subclass a base class that is returned from a Standard Library...
31
by: damacy | last post by:
hi, there. i have a problem writing a program which can obtain ip addresses of machines running in the same local network. say, there are 4 machines present in the network; , , and and if i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.