extraction operator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Taras_96

    extraction operator

    Hi all,

    Jesse Liberty writes:

    "cin.get() >>myVarOne >myVarTwo; // illegal

    The return value of (cin.get() >myVarOne) is an integer, not an
    iostream object."

    (http://newdata.box.sk/bx/c/htm/ch16.htm)

    I would think that that the reason why this wouldn't work is because
    cin.get() returns an int, not because (cin.get() >mVarOne) is an
    integer...

    Anyone agree?

    Taras
  • sk_usenet

    #2
    Re: extraction operator


    "Taras_96" <taras.di@gmail .comwrote in message
    Hi all,
    >
    Jesse Liberty writes:
    >
    "cin.get() >>myVarOne >myVarTwo; // illegal
    >
    The return value of (cin.get() >myVarOne) is an integer, not an
    iostream object."
    >
    (http://newdata.box.sk/bx/c/htm/ch16.htm)
    >
    I would think that that the reason why this wouldn't work is because
    cin.get() returns an int, not because (cin.get() >mVarOne) is an
    integer...
    Anyone agree?
    If mVarOne is an integral type then (cin.get() >mVarOne) would return an
    integer. The code won't even compile if mVarOne has any other type.

    --



    Comment

    • acehreli@gmail.com

      #3
      Re: extraction operator

      On Apr 30, 6:21 am, Taras_96 <taras...@gmail .comwrote:
      Hi all,
      >
      Jesse Liberty writes:
      >
      "cin.get() >>myVarOne >myVarTwo; // illegal
      >
      The return value of (cin.get() >myVarOne) is an integer, not an
      iostream object."
      The author probably means that "it will not work the way one might
      expect." It is illegal only if myVarOne or myVarTwo is uninitialized.
      (I don't remember whether the values must be less than or equal to the
      total bits in 'int'.)

      cin.get() >myVarOne

      is the result of an int shifted right by the value of myVarOne

      /* ... */ >myVarTwo

      is further shifting the result of the previous operation right some
      more.
      >
      (http://newdata.box.sk/bx/c/htm/ch16.htm)
      >
      I would think that that the reason why this wouldn't work is because
      cin.get() returns an int, not because (cin.get() >mVarOne) is an
      integer...
      The code should compile and work in that possibly unexpected way.

      Ali

      Comment

      • sk_usenet

        #4
        Re: extraction operator

        <acehreli@gmail .comwrote in message
        On Apr 30, 6:21 am, Taras_96 <taras...@gmail .comwrote:
        >Hi all,
        >>
        >Jesse Liberty writes:
        >>
        >"cin.get() >>myVarOne >myVarTwo; // illegal
        >>
        >The return value of (cin.get() >myVarOne) is an integer, not an
        >iostream object."
        >
        The author probably means that "it will not work the way one might
        expect." It is illegal only if myVarOne or myVarTwo is uninitialized.
        (I don't remember whether the values must be less than or equal to the
        total bits in 'int'.)
        I think (after looking at the link provided by OP) probably the author means
        that this code won't work the way "cin >mVar1 >mVar2" would have worked.

        <Quote from link>
        When you write cin >VarOne >varTwo >varThree;, the first extraction is
        evaluated (cin >VarOne). The return value from this is another istream
        object, and that object's extraction operator gets the variable varTwo. It
        is as if you had written this: ((cin >varOne) >varTwo) >varThree;
        </Quote from link>

        --



        Comment

        • James Kanze

          #5
          Re: extraction operator

          On Apr 30, 3:21 pm, Taras_96 <taras...@gmail .comwrote:
          Jesse Liberty writes:
          "cin.get() >>myVarOne >myVarTwo; // illegal
          The return value of (cin.get() >myVarOne) is an integer, not
          an iostream object."
          I would think that that the reason why this wouldn't work is
          because cin.get() returns an int, not because (cin.get() >>
          mVarOne) is an integer...
          Anyone agree?
          As others have pointed out, 1) it's not illegal (since myVarOne
          and myVarTwo have type char), but 2) it almost certainly doesn't
          mean what you want.

          I might add in general that, having taken a quick look at the
          page, it seems full of errors. I didn't read it in detail, but
          of the four or five sentences I did notice, about have were
          wrong. I don't think I'd recommend this text.

          --
          James Kanze (GABI Software) email:james.kan ze@gmail.com
          Conseils en informatique orientée objet/
          Beratung in objektorientier ter Datenverarbeitu ng
          9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

          Comment

          • Taras_96

            #6
            Re: extraction operator

            Thanks everyone - I didn't even think of the shift operator :)

            Taras

            Comment

            Working...