Skip to main content
GameDev.net gamedev.net
🔒 Locked

clearing input stream

Started by TEUTON Apr 1, 2006 at 4:10 AM 5 replies 700+ views
Original Post
TEUTON
TEUTON
Is there any standard way to clear input stream in C/C++??
Oxyd
Oxyd
Is
#include <iostream>#include <limits>...istream.ignore(std::numeric_limits<std::streamsize>::max());
what you’re looking for?
TEUTON
TEUTON
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.
Oxyd
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.
_goat
_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]

TEUTON
TEUTON
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??

_goat
_goat
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.