1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C++ Console Pause Function

Discussion in 'C++' started by packetpirate, Sep 7, 2010.

  1. packetpirate

    packetpirate New Member

    Sep 7, 2010
    Likes Received:
    Trophy Points:
    This is for the numerous people I see constantly asking how to "pause" the console after their code runs. The explanation for how the code works is within the snippet in comments.

    Basically, the "cin.clear();" function will clear the input stream, getting rid of any newline characters that would have made methods like using the "cin.get();" function to pause the console not work. Then, we have the "cin.ignore();" function. This will ignore the maximum amount of characters that can be entered into the stream (numeric_limits::max) be ignored, or wait for a newline character ( \n ). This way, the console will be "paused" until you enter a newline character (or the max. amount of characters for the input stream, but that would take forever and be unnecessary.)

    I hope this helps all of you C++ beginners who are either learning for yourselves or just getting started in a college course.

Share This Page