undefined identifier getch()

Stewart Gordon smjg_1998 at yahoo.com
Wed Dec 8 06:53:10 PST 2010


On 08/12/2010 11:06, Nrgyzer wrote:
> Hey guys,
>
> I'm writing a console based tool for windows. To receive the users input, I
> try to use getch() but the compiler always says "Error: undefined identifier
> getch". When I use getchar() it compiles successfully, but getchar() doesn't
> returns after a single input.

Under DMD 1, getch is declared in std.c.stdio.  So import that.

Under DMD 2, I don't know why it isn't there.  But you just need to add 
this declaration:

extern (C) int getch();

> Is there any equivalent version in D for getch?

D doesn't have its own API for console operations besides 
stdin/stdout/stderr stuff.  I guess it wasn't worth creating one partly 
because it would be a load of pointless wrappers around C functions, and 
partly because in these days where everyone uses GUI-based software 
they're not used as much.

Stewart.


More information about the Digitalmars-d-learn mailing list