redirecting cin
Phil Edwards
pedwards@disaster.jaj.com
Tue Dec 11 09:11:00 GMT 2001
On Tue, Dec 11, 2001 at 11:11:47AM -0500, Andrew Sutton wrote:
> MyParser parser;
> parser.parser( some_file_stream );
Like Bo says, MyParser::parser should accept an istream argument, not an
ifstream argument. Then, not only will reading from cin directly "just work"
but it will also open up possibilities for future expansion (e.g., derive
"iTCPIPstream" from istream and parse directly from network streams, etc).
> object. it works (worked) nicely until i upgraded to gcc 3.0.2 and lost the
> ability to grab the file descriptor from the streambuf. alas... okay enough
That misfeature is coming back in 3.1, in some form or another.
> the trouble is that it just doesn't work.
[...]
> worked great. now, since i don't get access to the file descriptor, i'm
> trying to redirect to cin, but like i said: doesn't work so great.
While I'm a big fan of error messages which are more easily readable, I
know for a fact that g++ never prints an error message anywhere close to,
"foo.cc:56: doesn't work so great".
Could you elaborate?
> int MyParser::parse( std::ifstream &file )
> {
> std::streambuf *in = std::cin.rdbuf( file.rdbuf() );
> yyparse();
> std::cin.rdbuf( in );
> }
What does g++ say when handed this code?
Phil
--
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace. We seek
not your counsel, nor your arms. Crouch down and lick the hand that feeds you;
and may posterity forget that ye were our countrymen. - Samuel Adams
More information about the Libstdc++
mailing list