Linux的等效为CONIO.H残培() [英] Linux Equivalent for conio.h getch()

查看:161
本文介绍了Linux的等效为CONIO.H残培()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

previously我使用C ++ / C编译器上支持窗口#包括< CONIO.H> 头文件,但在linux上我哪里有

Previously I use c++/c compilers on windows which support the #include<conio.h> header file but on linux where I have

gcc (Debian 4.9.2-10) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

编译器。而这种不支持#包括LT&;&CONIO.H GT; 头文件,因此我不能在我的程序中使用的getch()函数

compiler. And this doesn't support the #include<conio.h> header file and thus I can't use the getch() function in my program.

所以我想一个函数,它的工作原理完全为残培()。我不知道为什么我的编译器不支持头​​文件#包括LT&;&CONIO.H GT;

so I want a function which works exactly as getch(). I don't know why my compiler doesn't support the header file #include<conio.h>

净搜索后我得到了<一个href=\"http://stackoverflow.com/questions/1377403/alternative-function-in-iostream-h-for-getch-of-conio-h\">this它说, cin.get(); 可能是最接近的,但是这两个是在不同的方式,如果我们写的getch()不显示输入的字符上控制台而如果我们输入一个字符用cin.get()会显示在控制台上的字符。我不想要显示在控制台上的字符。

After searching on net I got this which says that cin.get(); is probably the closest equivalent but these two are different in the way that if we write getch() it does not display the character entered on the console whereas if we enter a character using cin.get() it displays the character on the console. I don't want the character to be displayed on the console.

使用的getchar()也显示在控制台上的字符。

using getchar() also displays the character on the console.

推荐答案

有若干更可移植这样做的不同方式。最简单的就是使用诅咒

There are a number of different ways of doing this more portably. The simplest is to use curses:

#include "curses.h"

int main() {
    initscr();
    addstr("hit a key:");
    getch();
    return endwin();
}

这篇关于Linux的等效为CONIO.H残培()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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