making my program sleep / wait / delay...

This is a discussion on making my program sleep / wait / delay... within the C++ Programming forums, part of the General Programming Boards category; Hi, basically, I am looking to put a pause into my program for about 1 second before doing a read. ...

  1. #1
    Matt Conway bobthebullet990's Avatar
    Join Date
    Nov 2005
    Location
    Cambridge
    Posts
    121

    making my program sleep / wait / delay...

    Hi, basically, I am looking to put a pause into my program for about 1 second before doing a read. How can i do this??? i know is c, its just sleep(ms); with unistd.h, but how to do it in c++???

  2. #2
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    you can use Sleep(ms); with #include <windows.h>

    edit:
    Here is more info on it: http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    > i know is c, its just sleep(ms); with unistd.h, but how to do it in c++???
    This is an API issue, not a language issue.

    The answer depends on the OS and compiler you're using more than the language.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Matt Conway bobthebullet990's Avatar
    Join Date
    Nov 2005
    Location
    Cambridge
    Posts
    121
    OK! ...So, how can i ensure that my code will work on both unix/linux and windows based systems, if they both use different libraries???

    is it something like

    #IFDEF

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    Well the sleep function (which waits in units of a second) is a POSIX-1 function which nearly all 32-bit operating systems support.

    It's in unistd.h on unix-like operating systems, but probably in something else on windows.
    So you might need conditional compilation around a header file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New, making a survey program
    By shaffer in forum C++ Programming
    Replies: 18
    Last Post: 12-01-2006, 10:36 AM
  2. why do we require sleep?
    By jinx in forum A Brief History of Cprogramming.com
    Replies: 43
    Last Post: 07-14-2004, 08:21 AM
  3. delay or sleep?
    By GanglyLamb in forum C Programming
    Replies: 17
    Last Post: 12-12-2002, 10:46 PM
  4. How to make a program wait for an event?
    By DRoss in forum C++ Programming
    Replies: 0
    Last Post: 09-10-2001, 01:13 PM
  5. How can I make a program wait for an event?
    By DRoss in forum C++ Programming
    Replies: 0
    Last Post: 09-06-2001, 09:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21