C++:尝试使用 ctime 在控制台中制作可重置时钟,但是
我尝试使用 ctime 制作一个可在控制台中重置的时钟,但由于某种原因,我的代码不会重置时间。按下触发按钮重置时钟后,结果是一个奇怪的数字,而不是0;
代码看起来像这样:
clock_t time = 0;
clock_t corrected = 0;
while(true) //event-driven loop
{
time = clock();
std::cout<<"clock: " << time - corrected << std::endl;
if( /*Key is press*/) corrected = clock();
}
I tried using ctime to make a clock that is resetable in a console, but for some reason, my code does not reset the time. After pressing the trigger button to reset the clock, the result is a weird number, rather than 0;
The code looks something like this:
clock_t time = 0;
clock_t corrected = 0;
while(true) //event-driven loop
{
time = clock();
std::cout<<"clock: " << time - corrected << std::endl;
if( /*Key is press*/) corrected = clock();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我这样做:
每次按
A
键时,输出都会重置为 0。问题出在您的按键测试上。If I do this:
The output resets to 0 everytime I press the
A
key. The problem is with your keypress testing.