How to KeyFlush?

This is a discussion on How to KeyFlush? within the C++ Programming forums, part of the General Programming Boards category; When using functions such as gets to input string, we normally use fflush(stdin) to Clear input buffer for next input. ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    12

    How to KeyFlush?

    When using functions such as gets to input string, we normally use fflush(stdin) to Clear input buffer for next input.
    But when using cin.getline, how to KeyFlush?

    TIA
    Nima

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    >we normally use fflush(stdin) to Clear input buffer for next input

    which is undefined. You can use something like -

    cin.ignore(80,'\n');

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    You can use something like - cin.ignore(80,'\n');
    That wont always work. The reason being that any operation on a failed stream is destined to fail. If the stream has its failbit set due to a string being entered when an int was expected for example you will have to call cin.clear() before cin.ignore() to ensure that the ignore operation succeeds.
    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

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21