Thread: system("Pause")

  1. #1
    #include <me!> Flakster's Avatar
    Join Date
    May 2005
    Location
    Canada
    Posts
    50

    system("Pause")

    I was wondering if it would be possible to create a pause that will only continue after a keystroke.

    Sort of like our little friend system("pause"), except, I don't want the text "Press any key to continue..."

    The user will be presented with, "When ready, press enter to fire." Then, when they press enter the next line will go off.

    Any ideas?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    This can only be done using non-standard functions. The actual solution depends on your OS and compiler, but it is probably something like getch() or _getch().

  3. #3
    #include <me!> Flakster's Avatar
    Join Date
    May 2005
    Location
    Canada
    Posts
    50
    I'm using Dev C++ 4.9.9.2
    OS: Windows XP

  4. #4
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Probably use cin.get() to wait for user to press enter.

    to use getch() make sure you include the header <conio.h>

    Here's a possibility...

    Code:
    #include <iostream>
    #include <windows.h>
    #include <string>
    
    using namespace std;
    
    void slow_type(char[]);
    
    int main()
    {
        char array[]="When ready press enter to fire";
        char array1[]="woot you have started the game";
        
        slow_type(array);
        cin.get(); // this is what to need
        slow_type(array1);
       
        
       
        
        cout<<"\n";
        system("pause");
    }  
    
    void slow_type(char stuff[])
    {
        int size = strlen(stuff);
        
        for (int i=0; i<size; i++)
        {
            cout<<stuff[i];
            Sleep(100);
        }
    }

  5. #5
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    try something like:

    Code:
    system("pause > tmp");

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed