Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Flush cin

Flush cin

Scheduled Pinned Locked Moved C / C++ / MFC
c++debuggingquestiondiscussion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andrew Walker
    wrote on last edited by
    #1

    Stupid, stupid question. Is there a way to completely flush cin of everything. A '/n' stays in the buffer if you ever use the stream extraction operators. The end goal is to replace the VC6 functionality of 'press any button to continue.' which is written out to the console in debug mode. It needs to be using only STL (using cin / streambufs etc), and it only needs to detect enter being pressed. I know I can use _kbhit(), but I'm annoyed enough to want someone to tell me what I'm missing. Bloody lecturers.


    If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling

    R J 2 Replies Last reply
    0
    • A Andrew Walker

      Stupid, stupid question. Is there a way to completely flush cin of everything. A '/n' stays in the buffer if you ever use the stream extraction operators. The end goal is to replace the VC6 functionality of 'press any button to continue.' which is written out to the console in debug mode. It needs to be using only STL (using cin / streambufs etc), and it only needs to detect enter being pressed. I know I can use _kbhit(), but I'm annoyed enough to want someone to tell me what I'm missing. Bloody lecturers.


      If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling

      R Offline
      R Offline
      Ryan Binns
      wrote on last edited by
      #2

      Try

      cin.ignore(numeric_limits::max());

      Ryan

      "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

      1 Reply Last reply
      0
      • A Andrew Walker

        Stupid, stupid question. Is there a way to completely flush cin of everything. A '/n' stays in the buffer if you ever use the stream extraction operators. The end goal is to replace the VC6 functionality of 'press any button to continue.' which is written out to the console in debug mode. It needs to be using only STL (using cin / streambufs etc), and it only needs to detect enter being pressed. I know I can use _kbhit(), but I'm annoyed enough to want someone to tell me what I'm missing. Bloody lecturers.


        If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling

        J Offline
        J Offline
        John R Shaw
        wrote on last edited by
        #3

        In the MFC Library is the following article: HOWTO: Clear an istream Object During Extraction ID: Q132422 INTP

        A 1 Reply Last reply
        0
        • J John R Shaw

          In the MFC Library is the following article: HOWTO: Clear an istream Object During Extraction ID: Q132422 INTP

          A Offline
          A Offline
          Andrew Walker
          wrote on last edited by
          #4

          Thanks, that was one of those questions where all the documentation seems to go round in circles, and you never find what you're looking for, but it's working now :-D


          If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups