在C ++中暂停程序执行5秒钟 [英] Pause program execution for 5 seconds in c++
本文介绍了在C ++中暂停程序执行5秒钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将c ++程序的执行暂停5秒钟。在android中,Handler.postDelayed具有所需的功能,我正在寻找。
I want to pause the execution of c++ program for 5 seconds. In android Handler.postDelayed has the required functionality what I am looking for. Is there anything similar to that in c++?
推荐答案
#include <iostream>
#include <chrono>
#include <thread>
int main()
{
std::cout << "Hello waiter" << std::endl;
std::chrono::seconds dura( 5);
std::this_thread::sleep_for( dura );
std::cout << "Waited 5s\n";
}
this_thread :: sleep_for
至少在指定的sleep_duration内阻止当前线程的执行。
this_thread::sleep_for
Blocks the execution of the current thread for at least the specified sleep_duration.
这篇关于在C ++中暂停程序执行5秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文