Borland getch() equivalent in Visual C++

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Archalien
Posts: 13
Joined: Fri Jan 23, 2004 8:07 pm
Location: Silicon Valley

Borland getch() equivalent in Visual C++

Post 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!!!
User avatar
talleyrand
Posts: 624
Joined: Mon Jul 21, 2003 6:56 pm
Location: Kansas City, MO, USA
Contact:

Post 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.
I choose to fight with a sack of angry cats.
Archalien
Posts: 13
Joined: Fri Jan 23, 2004 8:07 pm
Location: Silicon Valley

Post by Archalien »

thx 4 the :idea:
User avatar
bbadmin
Site Admin
Posts: 878
Joined: Mon Feb 17, 2003 8:54 pm
Contact:

Post 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
Post Reply