How do I delay an output in C++? I tried searching for similar questions, but I didn't find any solution which makes use of the 'ctime' library. Help please.
Asked
Active
Viewed 701 times
1
-
2This way of asking, you will have a "delay" in finding the answer – Khalil Khalaf Apr 03 '16 at 03:35
-
1You need to re-phrase your question and show what you have tried – cctan Apr 03 '16 at 03:48
-
You could use `std::time()` to get the current time an then use a loop until `std::time()` tells you that you have been looping for long enough? – Galik Apr 03 '16 at 03:48
-
Just a friendly tip, you may want to read over this page: [How-To-Ask Guide](https://stackoverflow.com/help/how-to-ask) so you can always be sure that your questions are easily answerable and as clear as possible. Be sure to include any efforts you've made to fix the problem you're having, and what happened when you attempted those fixes. Also don't forget to your code and any error messages! – Matt C Apr 03 '16 at 04:17
1 Answers
0
Have a look at this answer.
You could use std::this_thread::sleep_for(std::chrono::milliseconds(x));
For example:
#include <iostream>
#include <chrono>
#include <thread>
int main()
{
int x{3000};
std::cout << "Start waiting\n";
std::this_thread::sleep_for(std::chrono::milliseconds(x));
std::cout << "Done waiting\n";
return 0;
}