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.
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.