Thread: [Dev-C++] Cleaning the Input Buffer
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <and...@su...> - 2003-06-09 00:21:00
|
Dear users:
A)In C, I am using the following function for cleaning the input buffer:
clean_buffer();
void clean_buffer()
{
while(getchar()!='\n');
}
B)In C++ I thought who made this function was the "endl"
I´ve tested some codes like:
char string[80];
cin >> string; // here I put "hello there"
cout << string; // it prints "hello"
cin >> string // here it passes directly and loads in string
"there"
cout << string; // it prints "there"
...
cin >> string; // I put "hello there" again
cout << string << endl; // I´ve put "endl" expecting to avoid "there"
cin >> string; // it passes directly again :-(
cout << string; // it prints "there" again
My Question:
1) How to clean stdin using new C++ commands?
Regards
Andre
|
|
From: <or...@vp...> - 2003-06-09 08:52:53
|
André Macário Barros wrote: > My Question: > 1) How to clean stdin using new C++ commands? My Question: Why do you want new C++ commands? That'll only make things more complicated, they are slower, and will make your program bloated. The "old" C version is just fine. -- Greetings, Balázs |
|
From: Ioannis V. <iv...@em...> - 2003-06-09 10:48:54
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of OROSZI Balazs > Sent: Monday, June 09, 2003 11:53 AM > To: dev...@li... > Subject: Re: [Dev-C++] Cleaning the Input Buffer > > My Question: > Why do you want new C++ commands? That'll only make things more > complicated, they are slower, and will make your program bloated. > The "old" C version is just fine. In the contrary they are simpler, they should not be slower and make the program with less lines and more bullet-proof. Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |
|
From: Krzysztof K. <sa...@op...> - 2003-06-09 11:08:00
|
Witaj Ioannis,
W Twoim licie datowanym 9 czerwca 2003 (12:48:24) mo¿na przeczytaæ:
>> -----Original Message-----
>> From: dev...@li...
>> [mailto:dev...@li...] On Behalf
>> Of OROSZI Balazs
>> Sent: Monday, June 09, 2003 11:53 AM
>> To: dev...@li...
>> Subject: Re: [Dev-C++] Cleaning the Input Buffer
>>
>> My Question:
>> Why do you want new C++ commands? That'll only make things more
>> complicated, they are slower, and will make your program bloated.
>> The "old" C version is just fine.
IV> In the contrary they are simpler, they should not be slower and make the
IV> program with less lines and more bullet-proof.
Yes, for sure... And also some problems could happen when mixing stdio
and iostream code because of separated buffering, for example:
printf (" Something")
cout << " strange";
printf (" happened"); <= here stdout is flushed
cout << " with the string";
could produce:
Something happened strange with the string
I don't know if it is regulated by C++ standard, but some compilers
make code with "special effects" described above...
--
Pozdrowienia,
Krzysztof
mailto:sa...@op...
http://www.saveman.w.pl
|
|
From: <or...@vp...> - 2003-06-09 13:00:03
|
Krzysztof Kapuscik wrote:
> Yes, for sure... And also some problems could happen when mixing stdio
> and iostream code because of separated buffering, for example:
>
> printf (" Something")
> cout << " strange";
> printf (" happened"); <= here stdout is flushed
> cout << " with the string";
>
> could produce:
>
> Something happened strange with the string
>
> I don't know if it is regulated by C++ standard, but some compilers
> make code with "special effects" described above...
I never said to MIX code. I said, use what is simpler for YOU (the
original poster). If it works, why the hell ponder for hours on
something, that:
1. Does the same
2. More complicated for YOU (NOT Ioannis, NOT Krzysztof or ME)
--
Greetings,
Balázs
|
|
From: Abhijit S. <mu...@gm...> - 2003-06-09 19:55:53
|
Greets, Andre
-----Original Message-----
Dear users:
A)In C, I am using the following function for cleaning the input buffer:
clean_buffer();
void clean_buffer()
{
while(getchar()!='\n');
}
B)In C++ I thought who made this function was the "endl"
I´ve tested some codes like:
char string[80];
cin >> string; // here I put "hello there"
cout << string; // it prints "hello"
cin >> string // here it passes directly and loads in string
"there"
cout << string; // it prints "there"
...
cin >> string; // I put "hello there" again
cout << string << endl; // I´ve put "endl" expecting to avoid "there"
cin >> string; // it passes directly again :-(
cout << string; // it prints "there" again
My Question:
1) How to clean stdin using new C++ commands?
Regards
Andre
------------------------------
AFAIK, the cout and cin streams are totally independant; they do not share
the buffer. You can try code similar to your stdio:
while(cin.get() != '\n');
Untested, but should work. HTH.
________________________________________
Abhijit Shylanath
http://mudeth.tripod.com/
|
|
From: Ioannis V. <iv...@em...> - 2003-06-10 06:09:52
|
> My Question: > 1) How to clean stdin using new C++ commands? > > Regards > Andre cin.ignore(200, '\n'); Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |