cin.get();

This is a discussion on cin.get(); within the C++ Programming forums, part of the General Programming Boards category; What does this do at the end of a program?...

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

    cin.get();

    What does this do at the end of a program?

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    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, 06:32 PM
  3. Confused about cin.get(); and classes.
    By RaccoonKing in forum C++ Programming
    Replies: 6
    Last Post: 07-17-2005, 12:44 PM
  4. cin.get();
    By swgh in forum C++ Programming
    Replies: 2
    Last Post: 06-29-2005, 08: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21