#include <termios.h>
#include <unistd.h>
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
}
1、可以用while循环,一个菜单一个while循环,while循环里在套一个while循环;
2、例如:
cout<<"请选择:"cin>>choiceswitch(choice)
{
case '1':
{
while(run1)
{
cout<<"请选择:"cin>>x
switch(x)
{
case '1':
{
}
break
case '2':
{
}
break
case '0': //选择0是级可返回主菜单
{
run1=0
}
break
}
}
break
case '2':
{
}
break
case '3':
{
}
break
}