为啥Dev以前编写时加入getch()没事今天却提示undeclared

来源:百度知道 编辑:UC知道 时间:2024/06/13 17:19:25
以前的时候为了解决Dev-C++中程序运行一闪而过的问题,特地在程序末尾加一个getch();,自己甚至专门编写了一个程序用于产生带有这句话的源文件框架(省事),一直都相安无事。但是今天在两个包含了stdio.h的源文件里编译都出现了44 `getch' undeclared (first use this function) ,这是怎么回事?小弟刚用Dev不久,是不是有时候像Dev这样的编译器也会跟VC6一样发神经啊?

因为getch()这个函数声明在conio.h中,你要用这个函数,必须包含conio.h
我经常用这个函数,包含stdio.h没用,你可以自己查阅MSDN,我把MSDN上的给你copy过来让你看,其中getch()的功能和_getch()一样,我比较爱用_getch():

_getch, _getche
Get a character from the console without echo (_getch) or with echo (_getche).

int _getch( void );

int _getche( void );

Routine Required Header Compatibility
_getch <conio.h>
_getche <conio.h>

下面是微软的MSDN给出的一个例子:

Example

/* GETCH.C: This program reads characters from
* the keyboard until it receives a 'Y' or 'y'.
*/

#include <conio.h>
#include <ctype.h>

void main( void )
{
int ch;

_cputs( "Type 'Y' when finished typing keys: " );
do
{
ch = _getch();
ch = toupper( ch );
} while( ch != 'Y' );

_putch( ch );
_putch( '\r' ); /* Ca