-1

I have come across to a problem while coding in C++ on Dev C++ compiler. I want to delay my statement to some milliseconds, but the problem is dev doesnt support the dos.h header file and so its contents as well. I had an alternative way for using it with the help of for loop but i aint got its proper syntax in my mind to use it properly. I wish, you folks, might be able to resolve the problem for me. Thanks in Advance..

#include <dos.h>

int main(){

delay(1000)
cout << "Hello" 

return 0; 

Tell me another alternative way for this please.

Book Of Zeus
  • 49,509
  • 18
  • 174
  • 171
  • 2
    It helps to have a name to search for ... and < chrono > is probably the name to research. It turns out that < thread > also has a function or two of use to you. Review both on the en.cppreference.com site. (Hint - you might google for usage of a function called sleep - did you do any research?) – 2785528 Mar 15 '19 at 02:38
  • Possible duplicate of [Sleep function in C++](https://stackoverflow.com/questions/1658386/sleep-function-in-c) – eesiraed Mar 15 '19 at 05:13
  • Thanks alot, bro. I am actually a novice so i didnt make any research as i didnt even knkw what to do. Well i have sorted out the problem, thanks for the help again. – Muhammad Ahsan May 15 '19 at 10:43

3 Answers3

0

C++ has < thread >

< thread > has "std::this_thread::sleep_for(...)"

Example illustrating the (...)

std::this_thread::sleep_for(100ms);

The ms of 100 ms comes from

using  namespace std::chrono_literals;  // support suffixes like 100ms, 2s, 30 us

Probably you also need to include < chrono >

2785528
  • 5,438
  • 2
  • 18
  • 20
0

Use the header chrono and thread

#include <iostream>
#include <thread>
#include <chrono>
    using namespace std::this_thread; 
using namespace std::chrono; 
sleep_for(nanoseconds(10));
sleep_until(system_clock::now() + seconds(1));

You can change the nanoseconds part to seconds or keep it at nanoseconds, and the number beside it is the amount of that unit that you can change to any number.

-3

Use empty for loop for example:

for(int i=0; i<10000; i++);

Change upper bound according to your need.