text input buffer clearing

This is a discussion on text input buffer clearing within the C++ Programming forums, part of the General Programming Boards category; If I use cin and cout for text I/O, it appears that sometimes if you have two cin commands after ...

  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
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Check out cela's first post:

    cin Help...Sort of a noob Question?

  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
    RoD
    RoD is offline
    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-16-2010, 12:00 AM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 04:42 PM
  3. Confused about fgets, clearing the buffer, etc
    By caduardo21 in forum C Programming
    Replies: 1
    Last Post: 06-13-2005, 12:03 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10: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

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