注册 登录
编程论坛 C++教室

初学者求助,请问各位大神,getch()函数怎么加在程序里?

eric2012 发布于 2022-08-16 21:39, 1142 次点击
初学者求助,请问各位大神,getch()函数怎么加在程序里?
代码(简单概括):
#include<string>
#include<iostream>
#include<conio.h>
#include<cstdlib>
#include<ctime>
using namespace std;
int main(){
    ……
    ……
    while(1){
        cin>>c;
        system("cls");
        //加在这里
        switch(c){
            case ‘w’……
               ……//有含有return 0;的条件。
}
    return 0;
}为何加上以后要按“w”+Enter+“w”程序才能生效?
5 回复
#2
rjsp2022-08-17 07:25
请问各位大神,getch()函数怎么加在程序里?
你需要告诉大家 你想达到什么样的输入输出效果
#3
eric20122022-08-17 08:16
回复 2楼 rjsp
输入“w”无需按enter键即可输出
#4
rjsp2022-08-17 09:23
程序代码:
#include <stdio.h>
#include <conio.h>

int main( void )
{
    for( ; ; )
    {
        int ch = _getch();
        if( ch==0x00 || ch==0xE0 )
            _getch();
        else
        {
            switch( ch )
            {
            case 'w':
            case 'W':
                puts( "你按下了w键" );
                break;
            }
        }
    }
}
#5
eric20122022-08-18 17:28
回复 3楼 eric2012
为何放入程序后,系统提示程序无法正常工作???
#6
rjsp2022-08-18 18:10
以下是引用eric2012在2022-8-18 17:28:25的发言:

为何放入程序后,系统提示程序无法正常工作???

听不懂,什么叫“放入程序”,代码呢?
“系统提示程序无法正常工作”其实我也听不懂,编译链接信息呢?
1