Thread: cin.get();

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    3

    cin.get();

    What does this do at the end of a program?

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Grabs a character of input, like anywhere else in the program.

    http://cpwiki.sf.net/Pause_console

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    3
    When you say grabs the next character do you mean the return key stroke?

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    its grabs the next character of input. Regardless of what key it is. Pretty much it means if you hit ANY key on you keyboard it will continue.

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by Raigne View Post
    its grabs the next character of input. Regardless of what key it is. Pretty much it means if you hit ANY key on you keyboard it will continue.
    but input will NOT be processed till the user presses enter
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The assumption is that the input buffer is empty, and so when you call cin.get() the program waits for the user to type in a character. Since input isn't processed until the user hits enter, then the program waits until the user hits enter. This effectively pauses the program so that you can view the output before it finishes and the console window closes.

    The empty input buffer assumption doesn't always hold true, though, which is one of the most common reasons why cin.get() doesn't always work by itself to pause the program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cin.get(); not working with my switch statement
    By tenor_jazz13 in forum C++ Programming
    Replies: 2
    Last Post: 01-12-2008, 10:33 PM
  2. cin.get() problem
    By Cilius in forum C++ Programming
    Replies: 20
    Last Post: 07-28-2005, 05:32 PM
  3. Confused about cin.get(); and classes.
    By RaccoonKing in forum C++ Programming
    Replies: 6
    Last Post: 07-17-2005, 11:44 AM
  4. cin.get();
    By swgh in forum C++ Programming
    Replies: 2
    Last Post: 06-29-2005, 07:51 AM
  5. curiosity about cin.get() and cin.getline()
    By ssjnamek in forum C++ Programming
    Replies: 18
    Last Post: 11-30-2003, 01:26 AM