+ 3
What delay or sleep function can be used for c++ in code playground?
I've tried: sleep(), usleep(), nanosleep(), std::this_thread::sleep_for(std::chrono::milliseconds()). neither of them work, so which sleep/delay function is available for c++ in code playground?
8 Respostas
+ 12
The Playground does "support" delaying functions, as in they will run, but all it does is make your output take longer (and make it more likely for the server to cut the session short on you). You won't see the pause in output, because the result is sent back in one chunk of plain text.
+ 4
@Ace
Isn't using sleep(); bad practice?
+ 3
@Manual
using sleep() is frowned upon. i dont use it, instead i use this_thread::sleep_for(chrono::<unit>(value) ). that doesn't work, so i'm looking for a way to delay output within code playground.
+ 2
edit
They are used for slowing down your code or for timing sections of code.
+ 1
@Manual Sleep() allows your CPU to rest for a brief period, which significantly decreases CPU usage when you are executing something like an infinite loop. But if you are using it for timing stuff specifically, then yes it is a bad practice.
+ 1
@aklex timer is what i want to do/create, or are there timer functions in c++ that work on playground? if not how would i go about making a timer if there is no suitable sleep/delay function?