How to I make a delay in C++?

–1 vote
asked Jun 29, 2018 by BroudyMan (520 points)
#include <iostream>

using namespace std;

int main()

{

cout <<"Hello"<< endl;

//how do I delay?

cout <<"world."<< endl;

return 0;

}

2 Answers

0 votes
answered Jul 1, 2018 by anonymous
#include <stdio.h>
#include <unistd.h>

int main()
{
    for(int i=0;i<5;i++) {
      printf("Hi.."); 
      fflush(stdout);
      usleep(1000000); // wait for 1000000 micro seconds
    }

    return 0;
}
commented Jul 5, 2018 by yasser
i just tried to use" cout" instead of "printf" but it didn't work,do you know why?
commented Jul 7, 2018 by anonymous
cout << :Hi.."<<endl;
that's the c++ equivalent for printf
commented Jan 4 by Mahesh Morem (200 points)
you should also change the stdio.h as iostream.h
0 votes
answered Sep 28, 2018 by LeoSar
#include <iostream>
#include <chrono>
#include <thread>

int main()
{
    std::cout<<"Hello World\n";
    std::this_thread::sleep_for(std::chrono::milliseconds(20)); //delay
    std::cout << "Hello World Again\n";
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...