Thread: pause

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    47

    pause

    i know ther is a way to make the program stop and wate for you to press a butten like enter
    the bad thing is i dont know what this is can someone post it?

  2. #2
    Learn from the llama Marlon's Avatar
    Join Date
    Jun 2005
    Location
    South africa
    Posts
    25
    Use system("pause"); This is how I do it. Or include conio.h and use getch();
    `Who are YOU?' said the Caterpillar.
    This was not an encouraging opening for a conversation. Alice replied, rather shyly, `I--I hardly know, sir, just at present-- at least I know who I WAS when I got up this morning, but I think I must have been changed several times since then.' - Lewis Caroll's Alice in Wonderland.

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #4
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Marlon
    Use system("pause"); This is how I do it. Or include conio.h and use getch();
    This is the C++ forum bro :P

    Code:
    #include <iostream> // the library for cin, and cout
    
    using namespace std; // the namespace used from iostream
    
    cin.get(); // pauses the program
    If youve used cin in your program before and need to pause, youll need to put cin.ignore(); before that cin.get(); and it'll pause.

    This is probably in the FAQ as the above said.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  5. #5
    Registered User fuchu's Avatar
    Join Date
    Jun 2005
    Posts
    8

    Post

    Quote Originally Posted by Dae
    This is the C++ forum bro :P

    Code:
    #include <iostream> // the library for cin, and cout
    
    using namespace std; // the namespace used from iostream
    
    cin.get(); // pauses the program
    If youve used cin in your program before and need to pause, youll need to put cin.ignore(); before that cin.get(); and it'll pause.

    This is probably in the FAQ as the above said.
    cin.get(); only pauses after user input though doesn't it?

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    It'll pause UNTIL user input.

    system("pause") is often a bad idea because there is always the possibility that pause.exe doesn't exist, for a number of reasons.

    This is the C++ forum bro :P
    Despite being non-standard, conio.h is a very commonly used library. Personally, getch() is a function I'd definitely like to have if I was working with a console application.

  7. #7
    Registered User fuchu's Avatar
    Join Date
    Jun 2005
    Posts
    8
    I might do that... Maybe.

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    You might do what?

  9. #9
    Registered User fuchu's Avatar
    Join Date
    Jun 2005
    Posts
    8
    What you said.

  10. #10
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I didn't tell you to do anything.

  11. #11
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    cin.get() will sit and wait until the user hits the return key.

    You're probably better off using a function that read keystrokes directly. (eg getch() which lives in <conio.h> will get input from the keyboard directly, without echoing, with most windows compilers). Problem is, these function are non-standard (eg different names/headers for different compilers). But that's also true of a system() call.

  12. #12
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    The use of cin.get() can appear to be problematical (as can getchar(), part of <stdio.h>) as if there is any data left on the stream (say, for instance, a linefeed after reading in an integer value), get/getchar will return with that immediately. If you want to pause the input, use this:

    cin.sync();
    cin.get();

    sync flushes the stream.

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  13. #13
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    why not use cin.flush( );
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  14. #14
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    It might work just as well (heck, it may even do exactly the same thing, for all I know), I am in the habit of using sync.

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  15. #15
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    I only use system("pause") to end an external source file, so it loops back to the main().
    otherwise i use getch(). system("pause") is only really good when it is not connected to main(). An example is say a function had ened ie: void I_AM_A _BEAN()
    at the end of the function, since it is void you cannot use return 0 as you can't return to main if the function is decalred as void, so system pause would prompt the user to hit enter, then it would jump back to whatever it was before the function was called before.

    ie: return signpost();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Fork(), pause(), and storing PID's in a linked list
    By vital101 in forum C Programming
    Replies: 10
    Last Post: 09-28-2007, 02:16 AM
  3. Dev-C++ Compile and Run with Pause
    By xmltorrent in forum C++ Programming
    Replies: 12
    Last Post: 03-29-2006, 11:55 PM
  4. pause program at console
    By datainjector in forum C# Programming
    Replies: 1
    Last Post: 03-27-2003, 12:36 AM
  5. Pause function ???
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 09-02-2001, 08:22 PM