我想添加一個延遲,這樣一條線將會運行,然後在短暫的延遲之後,第二個會運行。我對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。 –