Quote Originally Posted by monarch_dodra View Post
Consider especially that some command-line programs' input stream are not the keyboard, but the raw output stream of other programs (think LAME.exe, x264.exe etc.). The side effect would be the program not stopping, and the stream being completely corrupted.

Of course, those aren't toy programs anymore [...]
Ok, these would be problematic. Actually, I have written a bunch of DOS console programs (in C) in the past that used some kind of pause function. As they would certainly get screwed up when stdout would be redirected (and that was a quite common scenario), I had the pause function check for the redirection and skip the actual pause if there was one. This involved IOCTL calls however, and thus was not portable. I think that's a reasonable effort for a non-toy program.

[...] but even for a toy program, try this:

Code:
int main()
{
    pause();
}
This is what my console looks like:

Code:
Please press enter...
hello world!<return>
What's up?<return>
-------End program
Hmmm... I think that's because the cin.ignore() call in laserlight's pause() implementation uses the '\n' as delimiter. Maybe a more sophisticated pause() could avoid this problem? Unfortunately I can't present one off-hand because of my limited iostream experience. Again, I would consider this to be an acceptable effort if the function is to be reused.

And yes, your second example gets screwed up too, but isn't that an abuse of the pause() function? I must admit, though, that it gets less screwed up if pause() simply calls system("pause").

Well, this is becoming a much bigger discussion than I ever imagined...