Kodewerx

Our culture has advanced beyond all that you could possibly comprehend with one hundred percent of your brain.
It is currently Thu Oct 23, 2025 12:23 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Mar 14, 2007 8:53 pm 
Offline
Kommunist
Kommunist

Joined: Mon Feb 12, 2007 4:24 pm
Posts: 29
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);


Last edited by lightsaber on Wed Mar 14, 2007 10:17 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Mar 14, 2007 9:58 pm 
Offline
Krew (Admin)
Krew (Admin)
User avatar

Joined: Sun Oct 01, 2006 9:26 pm
Posts: 3768
Title: All in a day's work.
If fflush doesn't work, you're SOL.

Try avoid using the lame C++ iostream, if you can. It's really garbage.

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Mar 14, 2007 10:20 pm 
Offline
Kommunist
Kommunist

Joined: Mon Feb 12, 2007 4:24 pm
Posts: 29
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 51 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group