• Advertisement
Sign in to follow this  

clearing input stream

This topic is 4348 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Is
#include <iostream>
#include <limits>

...

istream.ignore(std::numeric_limits<std::streamsize>::max());
what you’re looking for?

Share this post


Link to post
Share on other sites
By doing a little more search I came to know about a function in standard C which we can use for clearing input buffer

 rewind(stdin);

Here's the link
http://www.cplusplus.com/ref/cstdio/rewind.html

Which is better-your's or the rewind function.

Share this post


Link to post
Share on other sites
Yours is C, mine is C++ — if you’re using C you can only use rewind, if you’re using C++’s streams, you should use .ignore. If you’re using C I/O in C++ then rewind would be more apropriate, I guess.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oxyd
Yours is C, mine is C++ — if you’re using C you can only use rewind, if you’re using C++’s streams, you should use .ignore. If you’re using C I/O in C++ then rewind would be more apropriate, I guess you're doing it wrong.


Fixed. [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by _goat
Quote:
Original post by Oxyd
Yours is C, mine is C++ — if you’re using C you can only use rewind, if you’re using C++’s streams, you should use .ignore. If you’re using C I/O in C++ then rewind would be more apropriate, I guess you're doing it wrong.


Fixed. [smile]


Do you have a better method then??

Share this post


Link to post
Share on other sites
Oxyd gave a good solution - I'm just saying that if you're using C++, you should really be using the C++ I/O classes rather than the C functions.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement