RE: [Dev-C++] Cleaning the Input Buffer
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
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/
|