c ++结构:在某个定时器重复一组函数 [英] c++ structure: repeat set of functions at a certain timerate

查看:202
本文介绍了c ++结构:在某个定时器重复一组函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我坚持一个小c ++程序。我在w7环境中使用codeblocks。

我做了一个函数,显示一个ASCII地图和一个标记。第二个函数更新该地图上的标记位置。

I made a function witch 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 that the marker gets updated and the map showed, and this repeated at a certain time rate. Witch 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆