🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: att.lang.c++
Article #156

Re: cin.getline problem

#156
From: tony
Date: Tue, 02 Feb 1999 00:00
48 lines
1772 bytes
Hi Fredrik
Thanks, tried that still doesn't work. It only occurs when
typing in more chars than string length? I thought getline only accepted the
delimiter size ignoring the \n key.But the extra chars must be staying in
the keyboard buffer.
Heres the code:

int main()
{
char first[10];
char second[10];

for(int i=1; i<3;i++)
{
cout << "enter first name ";
cin.getline(first,10);
cout << "\nenter second name ";
cin.getline(second,10);
}



Fredrik Jangvik wrote in message <36B74810.3A6B118F@telia.com>...
>Hi Tony. Try this after the last line in the iteration.
>cin.ignore('\n', 100)
>
>/Fredrik
>
>tony wrote:
>>
>> Hi
>> Can anyone explain why this doesn't work?
>>
>> for(int i=1; i<3;i++)
>> {
>>     cout << "enter first name ";
>>     cin.getline(first,10);
>>    cout << "\nenter second name ";
>>    cin.getline(second,10);
>     cin.ignore('\n',100);   // Here that is.
>> }
>>
>> assuming vars are set up correctly etc. On the second iteration
>> it skips the first cin.getline but displays both couts and waits for
>> entry of second name. Do i need to flush the buffer after each getline if
so
>> how?
>> Thanks Tony
Technical Details
Message-ID: <k_Lt2.21218$%3.1550@wards>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <bo4t2.18070$%3.1222@wards> <36B74810.3A6B118F@telia.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d4ba,d6adead9ee0f9d93
X-Google-Attributes: gid10d4ba,public
From: "tony" <tony@netuk.force9.co.uk>
Subject: Re: cin.getline problem
Date: 1999/02/02
Message-ID: <k_Lt2.21218$%3.1550@wards>
X-Deja-AN: 439956491
References: <bo4t2.18070$%3.1222@wards> <36B74810.3A6B118F@telia.com>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
X-Complaints-To: abuse@plus.net.uk
X-Trace: wards 917998608 195.166.147.220 (Tue, 02 Feb 1999 23:36:48 BST)
NNTP-Posting-Date: Tue, 02 Feb 1999 23:36:48 BST
Newsgroups: att.lang.c++