Thread: text input buffer clearing

  1. #1
    rebmeM roinuJ
    Join Date
    Mar 2003
    Posts
    8

    Question text input buffer clearing

    If I use cin and cout for text I/O, it appears that sometimes
    if you have two cin commands after each other it appears that
    the input buffer isn't empty and the second cin command is ignored
    (because of a "leftover" carriage return or something in the buffer)

    I know that cin.get(); can fix some of these problems but if there
    is nothing in the buffer then it waits for a carriage return.

    So basically the thing I need is something that checks the buffer,
    deletes the things in it if anything and then just lets the program
    proceed that nothing has happened...

  2. #2
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

  3. #3
    rebmeM roinuJ
    Join Date
    Mar 2003
    Posts
    8
    Code:
    if (!cin)
        {
          cin.clear();
    
          while (cin.get() != '\n')
          {}
    
          continue;
        }
    Is it this you mean?

  4. #4
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Thats the one.

  5. #5
    rebmeM roinuJ
    Join Date
    Mar 2003
    Posts
    8
    Thanks! I'll test it... ...Tomorrow *yawn* clock is 22.24

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function in a text buffer
    By wellsper in forum C Programming
    Replies: 5
    Last Post: 04-15-2010, 11:00 PM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  3. Confused about fgets, clearing the buffer, etc
    By caduardo21 in forum C Programming
    Replies: 1
    Last Post: 06-13-2005, 11:03 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. How to put a Char into the Input buffer of a console?
    By Aidman in forum C++ Programming
    Replies: 10
    Last Post: 03-09-2003, 10:05 AM