首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在cygwin中包含conio.h?

如何在cygwin中包含conio.h?
EN

Stack Overflow用户
提问于 2015-05-25 01:22:08
回答 1查看 4.3K关注 0票数 1

我想在cygwin中使用getch();。所以我搜索了一下,添加了代码"conio.h“。

代码语言:javascript
复制
#include <termios.h>
#include <unistd.h>
#include <stdio.h>

/* reads from keypress, doesn't echo */
int getch(void)
{
    struct termios oldattr, newattr;
    int ch;
    tcgetattr( STDIN_FILENO, &oldattr );
    newattr = oldattr;
    newattr.c_lflag &= ~( ICANON | ECHO );
    tcsetattr( STDIN_FILENO, TCSANOW, &newattr );
    ch = getchar();
    tcsetattr( STDIN_FILENO, TCSANOW, &oldattr );
    return ch;
}

/* reads from keypress, echoes */
int getche(void)
{
    struct termios oldattr, newattr;
    int ch;
    tcgetattr( STDIN_FILENO, &oldattr );
    newattr = oldattr;
    newattr.c_lflag &= ~( ICANON );
    tcsetattr( STDIN_FILENO, TCSANOW, &newattr );
    ch = getchar();
    tcsetattr( STDIN_FILENO, TCSANOW, &oldattr );
    return ch;
}

在保存此代码"conio.h“之后,我不能使用getch();。错误消息是fatal error: conio.h:没有这样的文件或目录#include ^编译终止。

如何解决?

EN

回答 1

Stack Overflow用户

发布于 2015-05-25 02:08:12

任何其他想要使用conio.c文件中的函数的文件(应该是您所发布的文件的适当文件扩展名)都需要具有这些函数的原型。

具体地说,您需要第二个文件conio.h,如下所示;

代码语言:javascript
复制
#ifndef CONIO_H
#define CONIO_H

int getch( void );
int getche( void );

#endif // CONIO_H

在任何想要使用这些函数的文件中,conio.h文件必须是#include "conio.h“

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30426223

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档