getchar()函数不是很好用,
//-------------------------------------------------------------------- #
#include "stdafx.h"
#include "windows.h"
#include <iostream>
using namespace std;
#include <conio.h>
#define ESC_CODE 27
#define KEYB_UP 72
#define KEYB_DOWN 80
int _tmain(int argc, _TCHAR* argv[])
{
char ch;
printf("Push up or down key, Esc to exit program.\n");
do
{
switch(ch=getch())
{
case KEYB_UP:
printf("up\n");
break;
case KEYB_DOWN:
printf("down\n");
break;
}
}while(ch != ESC_CODE);
return 0;
}
//--------------------------------------------------------------------
上面这段代码就可以让Console处于等待输入状态了。
posted on 2008-12-18 19:39
BirdsHover 阅读(473)
评论(0) 编辑 收藏 引用