Thread: Press enter to continue

  1. #1
    Unregistered
    Guest

    Press enter to continue

    In my console programs i want to be able to pause the program. How do i make the program wait for the enter button to be pressed (without entering a char or number into a variable).
    Like the "Press enter to continue" thing....

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    Code:
    #include <cstdlib>
    using namespace std;
    
    ...
    
    system ("pause");

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    145

    Talking

    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int main()
    {
    
    cout<< "Hi there.\n";
    cout<< "Hit any key to exit program...";
    
    getch();  // This will pause the program until some key is hit
    
    return(0);
    }
    Hope that helps. Should work, that is what I always use.

  4. #4
    Registered User Sekti's Avatar
    Join Date
    Feb 2002
    Posts
    163

    here two

    /* Number 1 */
    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    int main()
    {
    cout<<"And you died..."<<endl;
    system("pause"); 
    /* 
    Note: only usable in dos:
    Reason: It calls the dos command 'pause' 
    */
    return 0;
    }
    Displays:

    And you died...
    Press any key to continue . . .

    /* Number 2 */
    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int main()
    {
    cout<<"And you died..."<<endl;
    cout<<"Press any key to continue . . ."<<endl;
    
    if(kbhit())
    {
    return 0;
    }
    
    return 0;
    }
    this uses the function kbhit() to see when a key is hit...
    Hope this helps....man I have no life when I typed all that to answer a question
    +++
    ++
    + Sekti
    ++
    +++

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help With a BlackJack Program in C
    By Jp2009 in forum C Programming
    Replies: 15
    Last Post: 03-30-2009, 10:06 AM
  2. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM
  3. Enistine program
    By Mac_the vamp in forum C Programming
    Replies: 2
    Last Post: 11-11-2002, 10:56 AM
  4. help on pressing enter to continue
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 10-06-2001, 11:08 AM
  5. Pause or press any key to continue
    By muffin in forum C Programming
    Replies: 3
    Last Post: 09-12-2001, 12:26 PM