Thread: Operator >> confusion

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    118

    Operator >> confusion

    Hi i am writting a rational number class which has overloaded operators.I am a bit confused woth the isstream operator because i am not sure how it fits in with my code.I want to be able to read in a string and parse it to where it belongs .if i do this
    Code:
      istream & Rational:: operator>>(istream &s,Rational c){
    
    
     }
    i do not know what to do.I know that the rational numbers input might look like this " 3/2 + 4/3 - 2 * 0" which represents just one rational number but i do not know if that should be passed in as in instream to the method argument and be tokenized and parsed to the member variables.
    Last edited by sigur47; 02-25-2012 at 04:06 AM.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    It's hard to say... my honest advice is that if you can't figure out what an operator should be doing, don't use an operator.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Why are your rational numbers represented by whole formulas? That's really over the top for a simple streaming operator.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ternary Operator to choose which operator to use
    By cncool in forum C Programming
    Replies: 7
    Last Post: 06-27-2011, 01:35 PM
  2. Replies: 3
    Last Post: 12-09-2008, 11:19 AM
  3. && and || operator confusion
    By rohit_second in forum C Programming
    Replies: 8
    Last Post: 09-02-2008, 12:10 AM
  4. Replies: 2
    Last Post: 07-07-2008, 03:46 AM
  5. Replies: 1
    Last Post: 07-07-2008, 03:38 AM