【发布时间】:2022-06-10 21:26:17
【问题描述】:
我正在测试我在这里看到的一个程序,用于在 c++ 中读取箭头键。它使用了一个名为“conio.h”的库,但由于我使用的是 macOS,因此我将其替换为“curses.h”,因为我听说它很相似。它具有我需要的相同功能(getch()),但是当我使用g++ test.cpp 编译它时,它抛出了以下错误:
.
可能是什么问题?我找到了一个可能的解决方案,但是由于我是 makefile 的新手并且只学习 c++,所以我不能把两个和两个放在一起。
#include <curses.h>
#include <iostream>
using namespace std;
int main()
{
int c, ex;
while(1)
{
c = getch();
if (c && c != 224)
{
cout << endl << "Not arrow: " << (char) c << endl;
}
else
{
switch(ex = getch())
{
case KEY_UP /* H */:
cout << endl << "Up" << endl;//key up
break;
case KEY_DOWN /* K */:
cout << endl << "Down" << endl; // key down
break;
case KEY_LEFT /* M */:
cout << endl << "Left" << endl; // key left
break;
case KEY_RIGHT: /* P */
cout << endl << "Right" << endl; // key right
break;
default:
cout << endl << (char) ex << endl; // not arrow
break;
}
}
}
return 0;
}
【问题讨论】:
-
链接时你
-lcurses了吗? -
Curses是一个带有头文件和库的包。您应该包括标题(完成)并与库链接。您需要为您的开发环境安装 Curses 包(如果存在)。
标签: c++ makefile compiler-errors header-files