conio.h is missing from Windows

a 夏天 提交于 2019-12-20 00:56:38

问题


I usually use VS but trying cygwin for the first time. I am using windows 7 but on compiling hello world program using gcc, it says "fatal error: conio.h: no such file or directory".

I am using Windows 7 and it seems conio.h is missing from my system. Can someone please tell me how to resolve this issue.

Thanks!!


回答1:


In Cygwin there doesn't exist any such header file called conio.h! Also, you don't need it either because it automatically holds screen for you without using getch() and for clrscr() you do have system("clear") in Cygwin!




回答2:


conio not being part of the standard library, you cannot expect it to be available cross-platform, or even between compilers on the same platform.

Being, non-standard, the name conio has been used by both Borland and Microsoft for libraries with differing APIs - Microsoft's is much smaller. So for that reason you might avoid it for portability.

It is not a matter of conio not being on Windows, Cygwin is a POSIX API layer and tool-chain for building and running POSIX code on Windows. The libraries provided with it are independent of those provided with Visual Studio.

There are a number of solutions including:

  • Use an alternative console I/O library, such as ncurses.
  • Use a conio source code implementation for Linux such as this (which uses ncurses and implements Borland's API).

The second solution is perhaps useful if you have a lot of legacy code using conio, but is overkill if you just want to prevent a console windows from closing. For that you could just use getchar() in any case and accept that you will have to press enter rather than any key.

If you are using Cygwin just to be able to use GCC on Windows, you might be better off using MinGW/GCC instead. This uses Microsoft's C runtime rather than GNU, and the Win32 API rather than POSIX.




回答3:


conio.h is a non-standard header provided by Borland's Turbo C compiler, which is a non-conforming C compiler itself. Cygwin, which is a windows emulation of unix-like environment, doesn't have it (Indeed, I am not aware of any other compiler that provides conio.h).

Can someone please tell me how to resolve this issue.

The best way to resolve it is to not use it at all :)

Instead, you could use ncurses if you want something that provides similar functionalities and compile it with:

gcc test.c -lncurses 


来源:https://stackoverflow.com/questions/25167605/conio-h-is-missing-from-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!