+ 1

Please tell me how to make a delay of 10 seconds in c++ code. Thank you in advance.

EN Please tell me how to make a delay of 10 seconds in c++ code. Thank you in advance. DE Bitte sagen Sie mir, wie man eine Verzögerung von 10 Sekunden in C ++ Code macht. Vielen Dank im Voraus. RU Подскажите пожалуйста, как сделать задержку на 10 секунд в коде c ++. Заранее спасибо.

18th Jan 2019, 2:26 PM
ReQiƞ
ReQiƞ - avatar
7 Answers
+ 4
When programming on Sololearn, the result is always sent in one go after the program terminates, so you won't be able to add a delay like that. Putting a sleep anywhere will just delay the whole output. Try this on your computer (if you need a C++ IDE, I suggest picking CodeBlocks). #include <iostream> using namespace std; int main(void) { cout << "Hallo, "; _sleep(10000); cout << "world"<< endl; return 0; } If it doesn't work, try using sleep() instead and adding either #include <windows.h> or #include <unistd.h> depending on your OS (Windows or Unix/Linux-based respectively).
18th Jan 2019, 3:00 PM
Zen
Zen - avatar
+ 2
Zen, thanks. The working version looks like this: https://code.sololearn.com/cGsa9f8rbi66/?ref=app . The "<unistd.h>" library and "sleep(!second!-no microsecond)" function are used. In the sololearn, it naturally does not work. This is the code I used: #include <iostream> #include <unistd.h> using namespace std; int main() { cout << "Hallo,"; sleep(10) ; cout << "world"<< endl ; return 0; }
18th Jan 2019, 6:59 PM
ReQiƞ
ReQiƞ - avatar
+ 1
sleep(10)
18th Jan 2019, 2:36 PM
Gordon
Gordon - avatar
18th Jan 2019, 2:50 PM
ReQiƞ
ReQiƞ - avatar
0
Zen, Rewa Mathur, thanks.
18th Jan 2019, 6:41 PM
ReQiƞ
ReQiƞ - avatar
0
Rewa Mathur, I used your code in a third-party program. He brought an error. Perhaps this is where it works, but not for me. What I posted is the only thing that pulls my program. Tomorrow I will try to run your code on the PC. I will definitely write about the result.
18th Jan 2019, 7:23 PM
ReQiƞ
ReQiƞ - avatar