kbhit()或getch()的问题 [英] Problem with kbhit() or getch()

查看:292
本文介绍了kbhit()或getch()的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,

我遇到问题 kbhit() getch()功能。





Hey,
I am having problem with kbhit() and getch() function.


//word = "Hello";
//Funtion is working fine but when I press a key it doesnot enter if(kbhit()) loop.
//Moreover, I tried _getch() next to "if" loop statement but _getch() is also not working :(
void Game::Print_LetterBox(int x,int y,char* word)
{
    int size = strlen(word);
    char key;

    if(_kbhit())
    {
        key = _getch();
    }
    for(int i=0;i<size;i++)
    {
        Letter_Box( word[i],x + i*34,y,"purple");
        for(int j=0;j&lt;size;j++)
        {
            if(word[j] == key)
                Letter_Box( word[i],x+i*34,y,"red");
        }
    }
    Animated_Character( x + size*34, 540 , 5);
}





任何帮助!!



Any help!!

推荐答案

I认为你的问题是如果不是循环 - 这是一次条件测试。如果测试通过,则执行下面的语句(或复合语句)中的代码。如果不是,则完全跳过该条件,并立即继续执行下一个语句。我怀疑你想在时使用,而不是,如果,它会循环。
I think your problem is that if is not a loop - it''s a one time conditional test. If the test passes, then the code in the statement (or compound statement) below it is executed. If it isn''t then the condition is skipped completely, and execution continues immediately with the next statement. I suspect that you want to use while rather than if which does loop.


这篇关于kbhit()或getch()的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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