| Kodewerx https://www.kodewerx.org/forum/ |
|
| Need help on clearing or flusing the input buffer on C https://www.kodewerx.org/forum/viewtopic.php?f=5&t=990 |
Page 1 of 1 |
| Author: | lightsaber [ Wed Mar 14, 2007 8:53 pm ] |
| Post subject: | Need help on clearing or flusing the input buffer on C |
How do you clear the input buffer? Code: int i = 0; std::cout << "Enter an integer "; std::cin >> i; For example the code above and the user enter a char instead of an integer. Anyway I already tried fflush (stdin) and std::cout << flush and it doesn't work either. EDIT: Never mind I got it to work now. Code: int ch;
cin.clear(); while ((ch = std::cin.get()) != '\n' && ch != EOF); |
|
| Author: | Parasyte [ Wed Mar 14, 2007 9:58 pm ] |
| Post subject: | |
If fflush doesn't work, you're SOL. Try avoid using the lame C++ iostream, if you can. It's really garbage. |
|
| Author: | lightsaber [ Wed Mar 14, 2007 10:20 pm ] |
| Post subject: | |
Parasyte wrote: If fflush doesn't work, you're SOL.
Try avoid using the lame C++ iostream, if you can. It's really garbage. I only used fflush because of the results that were presented to me by Google. Yes I will try to avoid using C++ iostream from now on. |
|
| Page 1 of 1 | All times are UTC - 8 hours [ DST ] |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|