🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

5 total messages Started by tony Sun, 31 Jan 1999 00:00
cin.getline problem
#153
Author: tony
Date: Sun, 31 Jan 1999 00:00
16 lines
959 bytes
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);
}

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
Re: cin.getline problem
#155
Author: Fredrik Jangvik
Date: Tue, 02 Feb 1999 00:00
50 lines
1947 bytes
This is a multi-part message in MIME format.
--------------26C1E3A8C84854535484E2F7
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

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
--------------26C1E3A8C84854535484E2F7
Content-Type: text/x-vcard; charset=us-ascii;
 name="jangvik.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Fredrik Jangvik
Content-Disposition: attachment;
 filename="jangvik.vcf"

begin:vcard 
n:Jangvik;Fredrik 
tel;home:0525-29929
x-mozilla-html:FALSE
adr:;;Aff�rsv�gen 16;457 30 TANUMSHEDE;;;Sverige
version:2.1
email;internet:jangvik@telia.com
title:Student of system analysis
x-mozilla-cpt:;-1
fn:Fredrik  Jangvik
end:vcard

--------------26C1E3A8C84854535484E2F7--
Re: cin.getline problem
#156
Author: 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
Re: cin.getline problem
#157
Author: Fredrik Jangvik
Date: Wed, 03 Feb 1999 00:00
99 lines
3125 bytes
This is a multi-part message in MIME format.
--------------6E030009BAB1C60CC71804C5
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Hi again Tony. Well, I tried too and it didn�t work like you said, so I
tried an other code. And well, when I tried it worked. So try this code
instead.

#include <iostream.h>
int main()
{
char first[10];
char second[10];

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

/Fredrik

tony wrote:
> 
> 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
--------------6E030009BAB1C60CC71804C5
Content-Type: text/x-vcard; charset=us-ascii;
 name="jangvik.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Fredrik Jangvik
Content-Disposition: attachment;
 filename="jangvik.vcf"

begin:vcard 
n:Jangvik;Fredrik 
tel;home:0525-29929
x-mozilla-html:FALSE
adr:;;Aff�rsv�gen 16;457 30 TANUMSHEDE;;;Sverige
version:2.1
email;internet:jangvik@telia.com
title:Student of system analysis
x-mozilla-cpt:;-1
fn:Fredrik  Jangvik
end:vcard

--------------6E030009BAB1C60CC71804C5--
Re: cin.getline problem
#158
Author: tony
Date: Fri, 05 Feb 1999 00:00
81 lines
2735 bytes
Hi again
Ok thanks that worked but, the user needs to
press return twice to get rid of the cin.ignore chars
not really an effective solution still need to find out why the buffer isn't
flushed i think?
Fredrik Jangvik wrote in message <36B86310.F20570E9@telia.com>...
>Hi again Tony. Well, I tried too and it didn�t work like you said, so I
>tried an other code. And well, when I tried it worked. So try this code
>instead.
>
>#include <iostream.h>
>int main()
>{
>char first[10];
>char second[10];
>
>for(int i=1; i<3;i++)
>{
>cout << "enter first name ";
>cin.getline(first,10);
>cin.clear();
>cin.ignore('\n',10);
>cout << "\nenter second name ";
>cin.getline(second,10);
>cin.clear();
>cin.ignore('\n',10);
>}
>}
>
>/Fredrik
>
>tony wrote:
>>
>> 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads