Thread: cleaning the buffer

  1. #1
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385

    cleaning the buffer

    in my program i use a menu - to get the value for the menu i use getch();, after this i use cin<< to get data from the user, the only problem is the charcter left over form the getch is in the space to type data, i have tried lots of ways but cannot get rid of it - any ideas?
    Monday - what a way to spend a seventh of your life

  2. #2
    Registered User cody's Avatar
    Join Date
    Sep 2001
    Posts
    86
    Hi,

    hmm memset() maybe?

    bye
    cody
    #include "reallife.h"

  3. #3
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    whats memset, i though that was something to do with memory allocation? how do i use that?
    Monday - what a way to spend a seventh of your life

  4. #4
    Registered User *pointer's Avatar
    Join Date
    Oct 2001
    Posts
    74
    After you use the value from getch, call cin.ignore(). That will clear the input stream buffer so that you can read another value.
    pointer = NULL

  5. #5
    Unregistered
    Guest
    If you KNOW there is only one char left in the buffer then use the syntax:

    cin.ignore();

    which uses the default partameters of 1 and newline char respectively. Otherwise, you can adjust at your discretion using the prototype:

    cin.ignore(int numberOfCharToIgnore, char terminatingChar);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  2. writing a pack-style function, any advices?
    By isaac_s in forum C Programming
    Replies: 10
    Last Post: 07-08-2006, 08:09 PM
  3. buffer contents swapping
    By daluu in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2004, 02:34 PM
  4. Tetris Questions
    By KneeGrow in forum Game Programming
    Replies: 19
    Last Post: 10-28-2003, 11:12 PM
  5. Console Screen Buffer
    By GaPe in forum Windows Programming
    Replies: 0
    Last Post: 02-06-2003, 05:15 AM