C++ Console Pause Function

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

  1. packetpirate

    packetpirate New Member

    Joined:
    Sep 7, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice