c++结构:以一定的时间速率重复一组函数 [英] c++ structure: repeat set of functions at a certain time rate
本文介绍了c++结构:以一定的时间速率重复一组函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我被一个小 C++ 程序困住了.我在 w7 环境中使用代码块".
我制作了一个显示 ASCII 映射和标记的函数.第二个函数更新该地图上的标记位置.
I made a function which shows a ASCII map and a marker. A second function updates the markers position on that map.
我想知道如何制作我的主要结构,以便更新标记并显示地图,并以一定的时间速率重复.我可以使用哪些功能来实现这一点.我应该遵循什么策略?
I would like to know how I could make my main structure so that the marker gets updated and the map showed, and this repeated at a certain time rate. Which functions can I use to make this happen. What strategy should I follow?
every x times/second DO { showmap(); updatePosition();}
我是 C++ 初学者,希望能帮到你!
I am a c++ beginner and I hope you can help!
推荐答案
带 usleep 的循环
A loop with usleep
unsigned XtimesPerSecond = 5; // for example
unsigned long long microseconds = 1000000 / XtimesPerSecond;
do
{
showmap();
updatePosition();
usleep(microseconds);
} while(true);
这篇关于c++结构:以一定的时间速率重复一组函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文