On Apr 22, 3:25 am, Jim Michaels <jmichae3REM...@THISPLEASEyahoo.com>
wrote:
Quote:
|
how do I write an overloaded >operator for istream that
|
Quote:
let's say fraction class through set() can take several types:
void set(char*)
void set(long int num, long int den)
void set(double)
|
Quote:
and that char* can handle hex strings, binary, and whatever C formatted
numbers you can throw at it, as long as it's a string.
|
You'll have to define a format, and read the text for it. Until
you've defined a format, there's not much one can say as to how
to read it.
Note that if you want to support both entering the number in the
form a/b, and as a decimal floating point, you're going to have
to resolve an ambiguity: is the string "42" the a of a/b, or is
it a floating point value? If you want the treatment of "42" to
depend on what follows (a "." or a "/"), you'll have to read the
characters into a temporary buffer, and then use istringstream
to convert this, once you know the format. (Note that if you
want to handle all of the different bases, this will be less
trivial than it might appear.)
--
James Kanze (Gabi Software) email:
james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34