5秒内迭代向量5

Iteration vector 5 in 5 seconds c

本文关键字:向量 迭代 5秒      更新时间:2023-10-16

如何在5秒内迭代向量5 ?

的例子:

for(int i = 0; i < count; i++) {
    cout << vector[count] << endl;
    //sleep 5 seconds
}

谢谢!

假设向量有5个元素:

#include <chrono>
#include <thread> /* introduced with c++11,
                     make sure your compiler is up to date
                     and is set to compile c++ with this version
                     of the STL and standard
                  */

<一口>

for (int i = 0; i < count; ++i)
{
    cout << vector[count] << endl;
    std::this_thread::sleep_for(std::chrono::seconds(1));
}

您也可以选择使用<windows.h>中的Sleep(n)