Note that there are some explanatory texts on larger screens.

plurals
  1. POClear input buffer including newline
    primarykey
    data
    text
    <p>I have a timer thread that executes five seconds in the future and a loop to wait for it to finish executing. Then the program finishes when the user hits enter. I noticed that while waiting for the loop, enter is accepted into the input buffer, and used to finish the program, and any subsequent enter hits are entered <em>onto the command line</em>! </p> <p>I want to ignore all input that was entered before "press enter to exit" including enter. It's been a while since I worked with C++ and I can't remember how to do this (I have searched SO and Google and can't find an answer to this specific question). Here is the my example:</p> <pre><code>std::cout &lt;&lt; "Timer test: wait 5 seconds\n"; boost::asio::io_service test_io; deadline_timer test_timer(test_io, posix_time::seconds(5)); int testInt = 0; auto asynctest = [&amp;testInt](const boost::system::error_code&amp;) { std::cout &lt;&lt; "Running asynctest()\n"; testInt = 5; }; std::cout &lt;&lt; "Starting asynchtest, which should output in 5 seconds\n"; test_timer.async_wait(boost::bind&lt;void&gt;(asynctest, boost::asio::placeholders::error)); while(testInt != 5) { std::cout &lt;&lt; ". "; boost::this_thread::sleep(boost::posix_time::milliseconds(200)); } // How do I clear all input from the input stream here so that if the user hit enter // during the timer countdown it will be cleared and user still must hit enter to // exit program? std::cout &lt;&lt; "Press enter to exit\n"; std::cin.ignore(80, '\n'); return 1; </code></pre> <p>adsf</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload