如何设置时间以差 1 秒输出数字
How to set time to output numbers by difference 1 second
我有一个这样的程序:
using namespace std;
int main()
{
srand(time());
int izlases_sk, a, b, c, d, e;
cout << "Enter 5 numbers" << endl;
cin >> a;
cin >> b;
cin >> c;
cin >> d;
cin >> e;
cout << endl;
for (int x = 0; x < 20; x++)
{
izlases_sk = rand() % 77;
cout << izlases_sk << "t";
if( izlases_sk == a || izlases_sk == b || izlases_sk == c || izlases_sk == d || izlases_sk == e)
cout << " You predicted this number!t";
else
cout << "Not";
{
if (a > 77 || b > 77 || c > 77 || d > 77 || e > 77)
goto end;
}
if ((x + 1) % 5 == 0)
cout<<endl;
}
end:
getch ();
}
我希望我的随机生成的数字一一输出,中间有 1 秒的延迟。我该怎么做?
示例:c++生成76
,然后在一秒钟后生成下一个数字。
使用 Sleep
函数(Windows 和 Linux 版本)
如果您
使用的是符合 C++11 的编译器,那么只需在您希望程序休眠一秒钟的任何位置插入以下行(您需要标头 <thread>
和 <chrono>
):
std::this_thread::sleep_for(std::chrono::seconds(1));
此外,此代码是可移植的。
相关文章:
- 在将数字随机生成为数组期间从内存输出随机数的数组
- 如何将输出数字划分为奇数和偶数
- 输出错误,问题是找到总和5000位数字cpp
- 遇到此问题时遇到困难:允许用户输入数组的值并使用 for,而循环也输出输入的最大数字
- 以C++输出一个数字三角形
- C++输出奇怪的字符而不是数字 (Windows)
- 一个C++程序,用于在输入位数时输出具有特定位数的 .txt 文件中的所有数字
- 反向输出数字 - c++
- 为什么当我输入一个大数字时,输出会一遍又一遍地重复?
- 未来值公式显示疯狂巨大数字的输出
- 输出一个数字,该数字可能是三种类型之一
- 编写一个程序,提示用户输入一个整数,然后输出数字的单个数字和数字的总和
- C++ cout 对齐输出数字
- 我同时使用了莱布尼茨和瓦利斯公式来估算π但输出数字错误,我不知道我哪里出错了
- C++文件输入/输出输出数字而不是字符
- 如何设置时间以差 1 秒输出数字
- c++将输出(数字)保存到一个数组中.一次两个数字
- c++输出数字而不是字符串
- 输出数字分组(1000000作为1,000,000,依此类推)
- C++ 覆盖 For 循环中的输出数字