Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conio.h is missing from Windows

Tags:

c

windows

conio

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!!

like image 682
Satya Ashok Kumar Avatar asked Oct 01 '22 03:10

Satya Ashok Kumar


2 Answers

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!

like image 140
Am_I_Helpful Avatar answered Oct 30 '22 12:10

Am_I_Helpful


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.

like image 24
Clifford Avatar answered Oct 30 '22 13:10

Clifford