我想添加一个延迟,这样一条线将会运行,然后在短暂的延迟之后,第二个会运行。我对C++相当陌生,所以我不确定我会怎么做。所以最好在下面的代码中打印“Loading ...”并等待至少1-2秒,然后再次打印“Loading ...”。目前它可以即时打印而不是等待。如何在C++中添加延迟代码。
cout << "Loading..." << endl;
// The delay would be between these two lines.
cout << "Loading..." << endl;
你忘了提到操作系统。在linux上,你可以使用unistd函数:'sleep(2)'? – Serge
哪个版本的C++?我宁愿使用'std :: this_thread :: sleep_for(std :: chrono :: seconds(2))'... – whoan
我正在使用C++ 11。 –