Thread: Pausing

  1. #1
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269

    Pausing

    No, this is not a "How do I keep my program from ending?" question. I don't even know if you can do this, but unlike system("PAUSE"); or cin.get(); and other various things to pause it, how do I get it to pause for a certain period of time? Like I want it to pause for 5 seconds and then do something else. Can I do this? If so, how?

    -SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Code:
    #include <windows.h>
    ...
    Sleep(5000); // sleep for 5 seconds
    gg

  3. #3
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    Are there any other ways of doing this? I haven't really learned Windows programming yet. So is there a way to do this on a console?
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    That works very well for console:
    Example
    Code:
    #include <windows.h>
    
    int main()
    {
        Sleep(5000); // Make the program pause for 5 seconds
        return 0;
    }

  5. #5
    Registered User
    Join Date
    Sep 2003
    Posts
    135
    Sleep() will work in a console if you're using a compiler with <windows.h>, even thought you're not creating a Windows GUI program.

    Typically, most if not all compilers provide some form of Sleep or Delay function. Or if you want to stick to standard functionality then you can write your own using the functionality in the <time.h> or <ctime> header.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >So is there a way to do this on a console?
    You can use Sleep in a console program.

    >Are there any other ways of doing this?
    You can either use a compiler extension (if one exists), or write your own hack that will likely be nonportable, nasty, and/or problematic in a multithreaded environment. Since the Win32 API Sleep function is standard among Windows systems, it would really be the best option.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pausing script to read output
    By a_priebe47 in forum C Programming
    Replies: 1
    Last Post: 06-15-2004, 10:16 PM
  2. pausing functions..
    By bluehead in forum C++ Programming
    Replies: 3
    Last Post: 01-13-2002, 03:27 AM
  3. Functions and pausing
    By dv916 in forum C++ Programming
    Replies: 4
    Last Post: 12-28-2001, 05:43 PM
  4. MS DOS not pausing while waiting for imput.
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 11-14-2001, 09:06 PM
  5. pausing the system
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 10-18-2001, 12:34 PM