简体   繁体   English

我的kbhit()在Mac上无法运行,正在制作PingPong游戏

[英]My kbhit() is not Working On Mac, Making a PingPong Game

I am trying to build a ping-pong game on my mac using C++14 (g++ in terminal) and I am getting this error: 我正在尝试使用C ++ 14(终端中的g ++)在我的Mac上构建一个乒乓游戏,并且出现此错误:

use of undeclared identifier 'kbhit'

here is the code: https://github.com/DemonJAZ/GamesC 这是代码: https : //github.com/DemonJAZ/GamesC

The function is in GameManager , class named Input . 该函数位于GameManager名为Input类中。

Since there is no sentence with a squiggly mark in the end, I took a liberty to invent a couple of my own. 由于最后没有句子带有弯曲的标记,所以我自由地发明了自己的几个。

Why am I getting this error? 为什么会出现此错误?

There is no kbhit function in the C++ language. C ++语言中没有kbhit函数。

Why am I seeing people using it all over the place? 为什么我看到人们到处使用它? Why does it work for them? 为什么对他们有用?

They are using it on Windows. 他们正在Windows上使用它。 It's a Windows function. 这是Windows功能。 You are on Mac OS X. 您使用的是Mac OSX。

I like to be able to use this function. 我喜欢能够使用此功能。 What should I do? 我该怎么办?

There are several options. 有几种选择。

  1. Develop on and for Windows, 在Windows上并针对Windows开发,
  2. Find a port (ie a re-implementation in a different environment) of this function that works on Unix-based systems. 查找该功能在基于Unix的系统上工作的端口 (即,在不同环境中的重新实现)。 I'm sure someone somewhere wrote one. 我确定某个地方有人写了一个。 Start with https://www.google.com/search?q=kbhit+mac and if this doesn't help, try https://www.google.com/search?q=kbhit+linux . https://www.google.com/search?q=kbhit+mac开始,如果这样做没有帮助,请尝试https://www.google.com/search?q=kbhit+linux In fact https://www.google.com/search?q=kbhit+ncurses will probably return the best results, but it's kinda hard to guess if you don't know exactly what to look for. 实际上, https://www.google.com/search?q=kbhit+ncurses可能会返回最佳结果,但是很难猜出您是否不知道要查找什么。
  3. When in Rome do as Romans do. 在罗马时,就像罗马人一样。 Write to the widely used Unix terminal API known as curses (you probably want the ncurses version). 写入被广泛称为curses的Unix终端API(您可能需要ncurses版本)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM