Can anyone help tell me what this does. I came across this in a program and I am unable to understand what it does. Would this be of any help in my programs, or can I live without it. Any help would be greatly appreciated...Thanks in advance.
Can anyone help tell me what this does. I came across this in a program and I am unable to understand what it does. Would this be of any help in my programs, or can I live without it. Any help would be greatly appreciated...Thanks in advance.
Next time maybe do a board and google search before asking.
Hope this help.
I've actually found the same site, and it tells me what it does. but i haven't found out why i need it. everytime i take it out of the program it gets stuck in a loop. Do i only need it if i'm going to scanf something after i've already scanf'd an arrary. once again, any help would be appreciated and thanks in advance for any you can give.
let's say that you asked the user to input a char, using getchar(), for some reason, the user enter more than one char, later, when you try to read another char, getchar() will return the extra char the user entered, to avoid this, you can use fflush(stdin), after reading the first char, and the second one will disappear.
And why you should not use fflush(stdin) is in the FAQ
As are a bunch of ideas on better ways to read input which don't involve the messyness of scanf()
But since you're using C++, perhaps you should consider the C++ equivalents.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
>But since you're using C++, perhaps you should consider the C++ equivalents.
cin's >> operator has the same issues as scanf, but C++ is different in that it has a standard solution equivalent to fflush on stdin:
Of course, this doesn't make it any cleaner (it simply isn't undefined behavior).Code:cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
My best code is written with the delete key.