redirecting cin
Andrew Sutton
ansutton@sep.com
Tue Dec 11 11:35:00 GMT 2001
On Tuesday 11 December 2001 02:18 pm, Phil Edwards wrote:
> On Tue, Dec 11, 2001 at 11:59:00AM -0500, Andrew Sutton wrote:
> > now, it seems that the issue is one of synchronization with stdin (used
> > by the parser to generate and read token streams). anyway, the
> > redirection happens at the streambuf layer. so, technically calls to cin
> > >> foo will take data from the open ifstream.
> >
> > that's all well and good - at least i figured out how to do it, but i
> > need calls to fread( stdin, ... ) or read( 0, ... ) to take data from the
> > open ifstream.
>
> Ah. Then you need to be affecting the C side of things, instead of /
> in addition to the C++ side. The C library for your platform is unaware
> of the redirection that's happening inside libstdc++, of course, so...
yup :)
> Hum. Not certain of a good way to do this in 3.0. For 3.1 you'll be able
> to extract the file descriptor and/or the FILE* and/or something else,
> and then use standard C library class on those.
after trying alot of different things, i've come to the conclusion that there
just isn't a graceful way to do it in 3.0.2. i've worked around it using a
temp file that gets opened using ::open() instead of as a file stream.
anyway, it works, but i'm not really happy with it. i liked being able to do
it gracefully in 3 lines... oh well. i'll roll it back when 3.1 comes back
out.
thanks for the help,
andrew sutton
ansutton@sep.com
More information about the Libstdc++
mailing list