Thread: Flushing cin buffer.

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    65

    Flushing cin buffer.

    Does anyone know how to flush the input buffer in C++? I was able to do it in C by fflush(stdin) in C I/O, but I could not find its counterpart in C++. I am using a lot of input operations in my file structures project and sometimes values which were previously inputted are inputted again due to this problem.

    Thanks for any help.
    The experimenter who does not know what he is looking for will not understand what he finds.
    - Claude Bernard

  2. #2
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    cin.flush;
    Monday - what a way to spend a seventh of your life

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    cin.flush does not exist. flush is an ostream member.

    to do what you want try this...
    Code:
    void flush(istream & is)
    {
    is.clear();
    is.ignore(80,'\n');
    }
    you can call it like this....

    flush(cin);
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    that probably explains why i couldnt get it to work in my code?
    Monday - what a way to spend a seventh of your life

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Flushing buffer
    By $l4xklynx in forum C Programming
    Replies: 6
    Last Post: 03-04-2009, 10:07 PM
  2. Need help flushing buffer
    By MSF1981 in forum C Programming
    Replies: 2
    Last Post: 02-15-2009, 07:30 PM
  3. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  4. buffer contents swapping
    By daluu in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2004, 02:34 PM
  5. Console Screen Buffer
    By GaPe in forum Windows Programming
    Replies: 0
    Last Post: 02-06-2003, 05:15 AM