CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Beginner's use of system("pause");

    Quote Originally Posted by monarch_dodra
    pauses are usually meant as a very quick and easy way to "debug" or "fix". (...) That is my 2 cents/conclusion: Use system("pause") when you need a quick pause for development reasons.
    Sounds like you should just set a breakpoint and run the program with a debugger.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  2. #17
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Beginner's use of system("pause");

    Quote Originally Posted by monarch_dodra View Post
    PS: Most distributed command line programs terminate when they finish running, they don't prompt you to press any key.
    Yes, fortunately they do! IMO the pause at the end of course is only useful for toy programs that mostly, if not always, are ran from the IDE.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #18
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Beginner's use of system("pause");

    Quote Originally Posted by Philip Nicoletti View Post
    Here is an interesting link on a (related) subject:

    http://www.daniweb.com/forums/thread90228.html
    Interesting. The solution developed by the OP in this thread looks really comprehensive. And it's quite complicated, as comprehensive solutions frequently are. It might actually work (didn't test it though) and it might actually be portable if placed inside a namespace.

    Quote Originally Posted by Paul McKenzie View Post
    There is a CodeGuru article written a couple of years ago that discusses this, and shows a pause() function equivalent that is safer to use. Don't have the URL link handy.
    You most probably mean http://www.codeguru.com/cpp/misc/mis...cle.php/c15893. The solution proposed there is stunningly simple. It uses _getch(), defined in conio.h, which I already mentioned as a possibility above. What is mentioned there, and what I didn't know so far, is that there might be an equivalent function named getch() under *nix. So, a portable pause function utilizing this concept might be constructed using #ifdef.

    As these low-lovel console I/O functions are independant from iostreams, this solution works with both test scenarios presented by monarch_dodra in post #7. (Yes I did test this.)

    The approach of registering the pause function as an exit handler using atexit() in this article even looked promising to solve the problem of not being able to observe destruction of global objects before the pause, but my hopes in that direction unfortunately got destroyed by MSDN.

    BTW, the author's logo at the article suggests that he is the guy who frequents the forums here as a moderator under the name Marc G. He likely will get a rating from me as soon as I come across one of his posts next time...

    EDIT: Corrected Marc G's user name and added link to his profile page. The guy without the space in the user name is a fresh junior member with zero posts...
    Last edited by Eri523; October 16th, 2010 at 08:40 AM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured