如何在c ++中一次运行两个函数? [英] how two functions run at a time in c++?

查看:108
本文介绍了如何在c ++中一次运行两个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的学生,用c ++开发一个项目。

我的项目是同时运行一个定时器功能和一个输入功能。

如果定时器功能超时然后功能中断代码,如果没有超时剂量,在限制期间,用户输入一个选项然后代码中断。

帮助我摆脱这个问题。谢谢



[edit]

i m student, working on a project in c++.
my project is to run a timer function and an input function simultaneously.
if timer function time out then function break code and if time out dose not occur ,during the limit, user input an option then the code break.
help me to get rid of this problem. thanks

[edit]

#include <iostream.h>
#include <sonio.h>
void timer() // if timer ends then goto point 
{
    int i=0;
    for(i=0; i < 60; i++)
    {
        delay(1000);
    }
    goto point;
}

void input(int ch)
 // if timer is running and durning time limit user input any choice than timper stops and go to point
{
    cin >> ch;
    goto point;
}
     
main()
{
    int ch;
    timer();
    input(ch);
point;
    getch();
}



[/ edit]


[/edit]

推荐答案

上述代码的任何内容都无效。你不能以你的方式从函数内部使用 goto 。您首先需要花更多时间研究C / C ++语言的基础知识。如果您对此感到满意,那么您可以继续学习多线程等高级主题。有关详细信息,请参阅 http://msdn.microsoft.com/en-us/library/3bstk3k5.aspx [ ^ ]和 http://msdn.microsoft.com/en-us/library/y6h8hye8(ⅴ = vs.100).aspx [ ^ ]。
Nothing much about the above code is valid. You cannot use goto from inside a function in the way you have. You first need to spend more time studying the basics of C/C++ languages. When you are comfortable with that then you can move on to advanced topics such as multithreading. For more information see http://msdn.microsoft.com/en-us/library/3bstk3k5.aspx[^] and http://msdn.microsoft.com/en-us/library/y6h8hye8(v=vs.100).aspx[^].


这篇关于如何在c ++中一次运行两个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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