按任意键返回(退出)

#include 
#include 
#include 

int getch()
{
    struct termios tm,tm_old;
    int fd = STDIN_FILENO,c;
	
	setbuf(stdin,NULL);
 
    if (tcgetattr(fd, &tm) < 0)
    {
        return -1;
    }
 
    tm_old = tm;
    cfmakeraw(&tm);
 
    if (tcsetattr(fd,TCSANOW, &tm) < 0)
    {
        return -1;
    }
 
    c = fgetc(stdin);
 
    if (tcsetattr(fd,TCSANOW,&tm_old) < 0)
    {
        return -1;
    }
    return c;
}
int main()
{
	system("clear");
	
	printf("按任意键退出。。。\n");
	getch();

	return 0;
}

你可能感兴趣的:(C++学习笔记)