Re: why cin.getline does not wait for an input?
From: Tim Roberts (timr_at_probo.com)
Date: 12/19/04
- Next message: Tim Roberts: "Re: why cin.getline does not wait for an input?"
- Previous message: Jerry Coffin: "Re: floating point mantissa?"
- In reply to: Geoff: "Re: why cin.getline does not wait for an input?"
- Next in thread: Duane Hebert: "Re: why cin.getline does not wait for an input?"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 18 Dec 2004 22:21:23 -0800
"Geoff" <Geoff@discussions.microsoft.com> wrote:
>
>Thank you very much very good, this was well worth the wait.
>
>Just out of curiosity, does the stream into cin share the memory on each
>time it's called, is it a union or something similar?
I'm not sure what you're asking. The buffer for cin is just a stream of
bytes. When you do this:
int i;
cin >> i;
The C++ compiler knows this is a "right shift" operator between an object
of type istream (or istreambuf or something like that) and an object of
type int. It searches for a function that takes those two parameters and
finds:
istream& operator>> (istream&, int);
It then includes a call to that function in your code. It is that function
that knows how to read characters from the stream and convert them to an
integer. Same thing happens with a different type. If you do this:
int i;
char str[40];
cin >> i >> str;
You get two calls. One to
istream& operator>>(istream&,int);
and one to
istream& operator>>(istream&,char*);
-- - Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc
- Next message: Tim Roberts: "Re: why cin.getline does not wait for an input?"
- Previous message: Jerry Coffin: "Re: floating point mantissa?"
- In reply to: Geoff: "Re: why cin.getline does not wait for an input?"
- Next in thread: Duane Hebert: "Re: why cin.getline does not wait for an input?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|