如何在C 中执行主程序时是否通过了一分钟是否通过
How to check in background whether a minute has passed while execution of the main program in c++?
我创建了一个程序,该程序在屏幕上显示当前时间。我现在想做的就是每分钟更新那个时间。
dateAndTime now; //created an object of a custom class dateAndTime
cout << "ntttttt" << now.hour() << ':' << now.minute() << endl;
cout << "CASH MANAGER" << "n";
cout << "1. Add cash" << "n";
cout << "2. Withdraw cash" << "nn";
int ch;
cout << "Enter a number 1 or 2: ";
cin >> ch;
让我们假设时间通过以下过程更新:
if (time(0) == now.epochTime() + 1)
now.setTime(time(0));
现在,我要做的是每分钟显示为now.hour() << ':' << now.minute();
的时间应更新,而不会延迟或中断主程序。
这意味着例如,如果用户在提示后几分钟不提供任何输入,则应在每分钟后自动更新时间,并且在整个过程中,程序始终在等待用户的输入(即主程序主机像往常一样运行)。有什么办法吗?我知道这样做可能没有跨平台技术。所以我只想为 windows os
做到这一点。
编辑:更新后不需要恢复当前光标位置或用户的任何书面文本(尚未输入)。
您可以使用alarm()
函数,该功能将在时间到期时发送信号SIGALRM
。
应用程序只需要为该信号带一个信号处理程序。
相关文章:
- 在提升multi_index容器中,是否定义了"default index"?
- cmath 是否借用了 math.h 的实现
- 检查是否安装了 windows10 C++
- sprintf(b, "%" ) 是否定义了?
- 它是否定义了哪些算法可以接受可变 lambda 的实现?
- std::bind 是否实现了 std::ref 和 std::cref 来消除函数调用的歧义?
- 是否通过向封闭对象的地址添加字节偏移量来访问子对象
- VS2017 是否更改了 C++ 中访问 C# 命名空间的方式?
- C++编译器是否优化了顺序静态变量读取?
- 我是否漏了记忆?
- 我是否访问了已释放的内存,或者在这种情况下DrMemory报告不正确?
- 如何检查是否定义了固定宽度的整数
- 如何检查用户是否输入了元音字符?
- 这是否错失了优化机会
- 如何检查在编译时是否调用了模板化方法?
- 在C++中,是否定义了删除基元类型(如通过 char* uint32_t)的行为
- 如何在C 中执行主程序时是否通过了一分钟是否通过
- 通过C强制转换访问结构的第一个字段是否违反了严格的别名
- 如何通过宏检查是否使用了GNU libstdc++
- 你如何(通过编程)知道Windows 7电脑上是否使用了大字体?