conio.h is missing from Windows
Asked Answered
S

2

7

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

Stomy answered 6/8, 2014 at 18:32 Comment(6)
There is no such header file in GCC. (Its not Turbo C++).Knapweed
Simple answer: Don't use it. If this doesn't help you: What function from <conio.h> do you need a replacement for?Tarmac
@Knapweed : conio is not exclusive to Turbo C++, Microsoft's VS2013 continues to to provide a conio API, which appears to be what he was previously using - of course not being standardised, it differs from Borland's conio!Filippa
I know..I am not using it. I needed a replacement for getch() and am now using getchar(). I was just curious is knowing as to why it wouldnt work Thanks!!Stomy
@Clifford; MSVC is not a C compiler.Knapweed
@haaks : I am not sure what your point is; Microsoft VC++ supports C compilation just as GCC supports both C and C++. Apart from that, it is academic, it is referred to in the question, and has a conio interface.Filippa
G
3

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!

Gurolinick answered 6/8, 2014 at 18:38 Comment(3)
@Shekhar..Thanks!! But the output screen is not holding. Thats why I was forced to use getch() and run into this missing conio.h trouble.Stomy
@SatyaAshokKumar-That's probably because of your code error or something like infinite loop. Please try executing hello world program and then comment!Gurolinick
@SatyaAshokKumar: You say "the output screen is not holding". Do you mean that the terminal window is vanishing immediately after the program runs? You can avoid that by running the program from a command line rather than by double-clicking its icon.Embouchure
F
1

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.

Filippa answered 6/8, 2014 at 19:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.