redirecting cin
Bo Thorsen
bo@sonofthor.dk
Tue Dec 11 08:46:00 GMT 2001
On Tuesday 11 December 2001 17:11, Andrew Sutton wrote:
> hi all,
>
> quick question (that may be dumb - or inappropriate, but i didn't know
> where else to post to. so if i'm wrong, sorry in advance)
>
> i have a bunch of different parsers in a collection. the parsers are
> flex/accent (like bison but parses context free grammars). the parser code
> is entirely written in C so i'm encapsulating the actual frontend parser in
> a shared library to be dynamically loaded when the executable needs it.
> this does a pretty good job avoiding collisions between the parser code
> (e.g. yytext). since the entire application is written in C++, i'm writing
> interfaces in C++ so i can just call:
>
> MyParser parser;
> parser.parser( some_file_stream );
Hold it right there, mister. Wrong design here, the parser method should take
a general inputstream instead of a filestream. No need for you to use one of
the specializations when you can just work on general input.
Then add an overloaded method to make an ifstream from a filename and call
that. And you will find that if you change the argument type to istream, it
will accept cin.
Bo.
--
Bo Thorsen | Praestevejen 4
Free software developer | 5290 Marslev
SuSE Labs | Denmark
More information about the Libstdc++
mailing list