C++关于程序运行时判断用户输入

如下代码所示
用到了 kbhit 函数,但是我这个程序运行起来我还没有输入f 他就直接给执行了,不知道时什么问题

#include<iostream>
#include<Windows.h>
#include<conio.h>
using namespace std;

bool test()
{
    while (kbhit)
    {
        char userInput = getch();
        if (userInput =='f')
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

int main()
{
    while (true)
    {
        if (test)
        {
            cout << "你点击了f,程序结束" << endl;
            return 0;
        }

        cout << "程序正在运行!" << endl;
        Sleep(1000);
    }

    system("pause");
    return 0;
}

kbhit,函数的意思是只要你输入一个数,他就默认非0.而且你的test 是一个函数,()

test是函数,改为if(test())。否则if(test)是判断函数地址是否为空,直接就向下执行了,不会执行test函数的