cin.get();

What does this do at the end of a program?
it just keeps the console window open so the user can see the output of the program.

it does so by getting the next character in the console
Last edited on
what do you mean by next character??
When using cin, you type in characters (keys on your keyboard) that appear in the command prompt. That's what your program - specifically, cin 0 reads. Normally, it will automatically take as many characters as it needs to input. For instance, if you say
 
cin >> myIntVar;


and you type 37643, it gets all 5 characters, treats them as an integer, and correctly puts 37643 into myIntVar.

By using cin.get(), you get only one of those characters, and it is treated as a char.

Sometimes, the command prompt will close as soon as the program finishes, meaning you can't see the output. Putting cin.get() forces the program to wait for the user to enter a key before it can close, and you can see the output of your program.
Topic archived. No new replies allowed.