Like Tree1Likes
  • 1 Post By CornedBee

Operator >> confusion

This is a discussion on Operator >> confusion within the C++ Programming forums, part of the General Programming Boards category; Hi i am writting a rational number class which has overloaded operators.I am a bit confused woth the isstream operator ...

  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 03:06 AM.

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,738
    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,893
    Why are your rational numbers represented by whole formulas? That's really over the top for a simple streaming operator.
    iMalc likes this.
    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, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21