Please tell me how to make a delay of 10 seconds in c++ code. Thank you in advance. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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
6 Respostas
+ 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