home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_07 / 1007055b < prev    next >
Text File  |  1992-05-21  |  583b  |  26 lines

  1. istream &operator>>(istream &is, rational &r)
  2.         {
  3.         long n, d;
  4.         char c = 0;
  5.         if (is >> c && c == '(')
  6.             {
  7.             is >> n >> c;
  8.             if (c == '/')
  9.                 is >> d >> c;
  10.             if (c != '(')
  11.                 {
  12.                 is.putback(c);
  13.                 is.clear(ios::failbit);
  14.                 }
  15.             }
  16.         else
  17.             {
  18.             is.putback(c);
  19.             is >> n;
  20.             d = 1;
  21.             }
  22.         if (is)
  23.             r = rational(n, d);  
  24.         return is;
  25.         }
  26.