Page 1 of 1

Borland getch() equivalent in Visual C++

Posted: Sat Jan 24, 2004 7:38 am
by Archalien
Is there a Visual C++ equivalent to Borlands:

conio.h

getch()

to keep a console program from closing at the end of execution???

I saw another post here that uses a request for a dummy variable, but I was hoping for a better method than that.

Any help appreciated!!!

Posted: Sat Jan 24, 2004 2:13 pm
by talleyrand
What, you don't like my hack? ;)

Well, I decided to ask an old friend (google) what they thought and here's what I found.
#include <stdio.h>
ought to have a getchar() function
#include <stdlib.h>
also has a system ("PAUSE");

I don't have 6.0 installed anymore so I can't actually test it but it seems probable.

Posted: Sun Jan 25, 2004 6:39 am
by Archalien
thx 4 the :idea:

Posted: Sun Jan 25, 2004 9:26 am
by bbadmin
With MSVC, I always use this:

#include <io.h>
char c;
_read(0, &c, 1);

Of course, that's not portable, so "_read" must be "read", with Borland, and with gcc it becomes:

#include <unistd.h>
char c;
read(0, &c, 1);

Keith MacDonald
Helios Software Solutions