c语言怎样结束控制台程序

c语言怎样结束控制台程序,第1张

类似这样:

#include <stdio.h>

#include <stdlib.h>

void shutdown()

{

    char type

    printf ("您确定退出吗?(Y/N)")

    fflush(stdin)

    scanf ("%c", &type)

    if (type=='Y' || type=='y')

        exit(0)

}

int main()

{

    int a

    while (scanf ("%d", &a)!=EOF){

        if (a==4){

            shutdown()

        }

    }

    return 0

}

对ESC键所对应的的ascll码,对它进行监听,然后调用系统退出函数

这个是试验过的!

#include<iostream>

#include<conio.h>

using namespace std

void main(){

char ch

ch=getch()

if(ch==27){

exit(1)

}else{

cout<<"你输入错误了"

}

system("pause")

}

这么写就行了using System

class Program

{

static void Main(string[] args)

{

Console.WriteLine("按a键退出")

while (Console.ReadKey().KeyChar != 'a')

{

}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/7863042.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存