View Single Post
Old Apr 18th, 2007, 10:20 PM   #12
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
'flush' is for output streams. ignore will ignore (get rid of) a specified number of characters in an input stream. There are a couple of overloaded versions. The use of cin.sync () is effective in many systems, but there is some question of it being a standard thing. I honestly can't comment on that part. Reading random comments on the purpose of cin.get is hardly as effective as just turning to the documentation.

To expand on Mel's comment, which is correct: PROGRAMS ARE DESIGNED TO TERMINATE WHEN DONE. If you launch your program from the command line, the window belongs to the command interpreter. When your program terminates, the window remains (it belongs to the command interpreter) and you get a new prompt. You can also see what went before.

If you have an IDE that executes the program in it's OWN window, then when the program terminates, its window goes away. What to do? What to do? CHANGE THE TERMINATION REASON. Make it terminate on user input. Input comes from a stream. Make sure it's empty, or input will be seen, it will terminate, the window will go bye-bye.

Why is there junk input? Because one asked for input of a specified kind. The user entered more than that (if only by pressing the ENTER key, which is required to be present before input is injected into the stream). Don't want it there? Get it out.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote