Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » C++
  • » fflush equivalent in c++? [RSS Feed]

#1 June 20, 2011 11:07:49

dayofthunder
Registered: 2011-06-20
Posts: 2
Reputation: +  0  -
Profile   Send e-mail  

fflush equivalent in c++?

Is there a fflush(stdin) equivalent in C++?
I want to empty input buffer after scanf();

Offline

#2 June 20, 2011 11:18:19

valerii
Registered: 2011-06-18
Posts: 22
Reputation: +  1  -
Profile   Send e-mail  

fflush equivalent in c++?

dayofthunder
Is there a fflush(stdin) equivalent in C++?
I want to empty input buffer after scanf();



Clearing input buffer with fflush() is not recommended. Even if you have learned to do this at school or university. Buffers depend on system dispatchers. So what you want to achieve is the following, remove pending input before end of line:

C++:

#include <iostream>
#include <limits>
using namespace std;

cin.ignore( numeric_limits <streamsize> ::max(), '\n' );


read more on this topic => fflush not recommended [faq.cprogramming.com]

Stay tuned!
Sharon

Offline

#3 June 20, 2011 11:35:31

dayofthunder
Registered: 2011-06-20
Posts: 2
Reputation: +  0  -
Profile   Send e-mail  

fflush equivalent in c++?

valerii
dayofthunder
Is there a fflush(stdin) equivalent in C++?
I want to empty input buffer after scanf();

Clearing input buffer with fflush() is not recommended. Even if you have learned to do this at school or university. Buffers depend on system dispatchers. So what you want to achieve is the following, remove pending input before end of line:

C++:

#include <iostream>
#include <limits>
using namespace std;

cin.ignore( numeric_limits <streamsize> ::max(), '\n' );


read more on this topic => fflush not recommended [faq.cprogramming.com]

Stay tuned!
Sharon


Yeah, the problem with the buffers. This is always confusing.

Thank you Sharon!

Offline

  • Root
  • » C++
  • » fflush equivalent in c++? [RSS Feed]

Board footer

Moderator control

Enjoy the 22nd of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support