By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,184 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,184 IT Pros & Developers. It's quick & easy.

extraction operator

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Taras_96" <ta******@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.

--
http://techytalk.googlepages.com
Jun 27 '08 #2

P: n/a
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
Jun 27 '08 #3

P: n/a
<ac******@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>

--
http://techytalk.googlepages.com
Jun 27 '08 #4

P: n/a
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."
(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?
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:ja*********@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
Jun 27 '08 #5

P: n/a
Thanks everyone - I didn't even think of the shift operator :)

Taras
Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.