I suggest this:
#include <iostream> #include <ctime> using namespace std; int main() { double tim; tim = time(0); while(time(0) - tim != 2) { } cout << "hello world"!; while (time(0) - tim != 2) { } }
Are there any other options?
I suggest this:
#include <iostream> #include <ctime> using namespace std; int main() { double tim; tim = time(0); while(time(0) - tim != 2) { } cout << "hello world"!; while (time(0) - tim != 2) { } }
Are there any other options?
#include <unistd.h> ... ... sleep(2);//2 ΡΠ΅ΠΊΡΠ½Π΄Ρ usleep(1000000);//1 ΡΠ΅ΠΊΡΠ½Π΄Π° (1.000.000 ΠΌΠΈΠΊΡΠΎΡΠ΅ΠΊΡΠ½Π΄)
It is necessary to take into account that by checking these functions printf is necessary either to finish the print on "\n"
, or to install flush immediately after the print: fflush(stdout);
, eg:
printf("1"); fflush(stdout); sleep(1); printf(" - 2");
The same goes for cout. Analog to fflush (stdout) - cout.flush ();
PS In Windows, this is not the case, but there is a replacement:
#include <windows.h> Sleep(1000);//1 ΡΠ΅ΠΊΡΠ½Π΄Π° - 1.000 ΠΌΠΈΠ»Π»ΠΈΡΠ΅ΠΊΡΠ½Π΄
A canonical C ++ way is to use std::this_thread::sleep_for
#include <chrono> #include <thread> int main() { std::this_thread::sleep_for(std::chrono::seconds(2)); }
Starting with C ++ 14 you can write
using namespace std::literals; std::this_thread::sleep_for(2s);
sleep () and delay () is a nice little article.
#include <iostream> int main(){ using namespace std; for (float ex = 0; ex <=4; ex=ex+0.10) { system("cls"); cout<<"Exit through 4 second"<<endl; cout<<" "; } exit(0); return 0; }
As an option)
Source: https://ru.stackoverflow.com/questions/23284/
All Articles