delay(int milliseconds) in Visual C++?

This is a discussion on delay(int milliseconds) in Visual C++? within the C++ Programming forums, part of the General Programming Boards category; Hi. What functions are there in Visual C++ which is similar to delay(int milliseconds) of Turbo C++? I am making ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    7

    Question delay(int milliseconds) in Visual C++?

    Hi.

    What functions are there in Visual C++ which is similar to delay(int milliseconds) of Turbo C++?

    I am making a simple DOS EXE using Visual C++ and needs to delay/wait for a few seconds between the functions.

    Thanks in advance.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    Code:
    #include <time.h>
    void wait(unsigned timeout)
    {
      timeout += std::clock(); 
      while(std::clock() < timeout) continue;
    }
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  3. #3
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    169
    The Sleep function suspends the execution of the thread.

    #include <windows.h>

    Sleep(1000); // wait 1 second

  4. #4
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    Code:
    #include <time.h>
    void wait(unsigned timeout)
    {
      timeout += std::clock(); 
      while(std::clock() < timeout) continue;
    }
    That's really a last resort since it doesn't care about other threads/processes and probably isn't as efficient as a compiler specific function that does the same thing. Since the best option is a nonportable function, you should wrap your own function around it and use that, then you only have to make one change when you port the program
    Code:
    // Tc++
    #include <dos.h>
    
    void wait(long msecs)
    {
        delay(msecs);
    }
    
    // Vc++
    #include <windows.h>
    
    void wait(long msecs)
    {
        Sleep(msecs);
    }
    p.s. What the alphabet would look like without q and r.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 07:13 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM

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